[DXGI]
[reactos.git] / reactos / dll / directx / wine / dxgi / surface.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 "dxgi_private.h"
21
22 /* Inner IUnknown methods */
23
24 static inline struct dxgi_surface *impl_from_IUnknown(IUnknown *iface)
25 {
26 return CONTAINING_RECORD(iface, struct dxgi_surface, IUnknown_iface);
27 }
28
29 static HRESULT STDMETHODCALLTYPE dxgi_surface_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
30 {
31 struct dxgi_surface *surface = impl_from_IUnknown(iface);
32
33 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
34
35 if (IsEqualGUID(riid, &IID_IDXGISurface)
36 || IsEqualGUID(riid, &IID_IDXGIDeviceSubObject)
37 || IsEqualGUID(riid, &IID_IDXGIObject)
38 || IsEqualGUID(riid, &IID_IUnknown))
39 {
40 IDXGISurface_AddRef(&surface->IDXGISurface_iface);
41 *out = &surface->IDXGISurface_iface;
42 return S_OK;
43 }
44
45 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
46
47 *out = NULL;
48 return E_NOINTERFACE;
49 }
50
51 static ULONG STDMETHODCALLTYPE dxgi_surface_inner_AddRef(IUnknown *iface)
52 {
53 struct dxgi_surface *surface = impl_from_IUnknown(iface);
54 ULONG refcount = InterlockedIncrement(&surface->refcount);
55
56 TRACE("%p increasing refcount to %u.\n", surface, refcount);
57
58 return refcount;
59 }
60
61 static ULONG STDMETHODCALLTYPE dxgi_surface_inner_Release(IUnknown *iface)
62 {
63 struct dxgi_surface *surface = impl_from_IUnknown(iface);
64 ULONG refcount = InterlockedDecrement(&surface->refcount);
65
66 TRACE("%p decreasing refcount to %u.\n", surface, refcount);
67
68 if (!refcount)
69 {
70 IDXGIDevice_Release(surface->device);
71 HeapFree(GetProcessHeap(), 0, surface);
72 }
73
74 return refcount;
75 }
76
77 static inline struct dxgi_surface *impl_from_IDXGISurface(IDXGISurface *iface)
78 {
79 return CONTAINING_RECORD(iface, struct dxgi_surface, IDXGISurface_iface);
80 }
81
82 /* IUnknown methods */
83
84 static HRESULT STDMETHODCALLTYPE dxgi_surface_QueryInterface(IDXGISurface *iface, REFIID riid,
85 void **object)
86 {
87 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
88 TRACE("Forwarding to outer IUnknown\n");
89 return IUnknown_QueryInterface(This->outer_unknown, riid, object);
90 }
91
92 static ULONG STDMETHODCALLTYPE dxgi_surface_AddRef(IDXGISurface *iface)
93 {
94 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
95 TRACE("Forwarding to outer IUnknown\n");
96 return IUnknown_AddRef(This->outer_unknown);
97 }
98
99 static ULONG STDMETHODCALLTYPE dxgi_surface_Release(IDXGISurface *iface)
100 {
101 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
102 TRACE("Forwarding to outer IUnknown\n");
103 return IUnknown_Release(This->outer_unknown);
104 }
105
106 /* IDXGIObject methods */
107
108 static HRESULT STDMETHODCALLTYPE dxgi_surface_SetPrivateData(IDXGISurface *iface,
109 REFGUID guid, UINT data_size, const void *data)
110 {
111 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
112
113 return E_NOTIMPL;
114 }
115
116 static HRESULT STDMETHODCALLTYPE dxgi_surface_SetPrivateDataInterface(IDXGISurface *iface,
117 REFGUID guid, const IUnknown *object)
118 {
119 FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
120
121 return E_NOTIMPL;
122 }
123
124 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetPrivateData(IDXGISurface *iface,
125 REFGUID guid, UINT *data_size, void *data)
126 {
127 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
128
129 return E_NOTIMPL;
130 }
131
132 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetParent(IDXGISurface *iface, REFIID riid, void **parent)
133 {
134 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
135
136 TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
137
138 return IDXGIDevice_QueryInterface(This->device, riid, parent);
139 }
140
141 /* IDXGIDeviceSubObject methods */
142
143 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDevice(IDXGISurface *iface, REFIID riid, void **device)
144 {
145 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
146
147 TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device);
148
149 return IDXGIDevice_QueryInterface(This->device, riid, device);
150 }
151
152 /* IDXGISurface methods */
153 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDesc(IDXGISurface *iface, DXGI_SURFACE_DESC *desc)
154 {
155 FIXME("iface %p, desc %p stub!\n", iface, desc);
156
157 return E_NOTIMPL;
158 }
159
160 static HRESULT STDMETHODCALLTYPE dxgi_surface_Map(IDXGISurface *iface, DXGI_MAPPED_RECT *mapped_rect, UINT flags)
161 {
162 FIXME("iface %p, mapped_rect %p, flags %#x stub!\n", iface, mapped_rect, flags);
163
164 return E_NOTIMPL;
165 }
166
167 static HRESULT STDMETHODCALLTYPE dxgi_surface_Unmap(IDXGISurface *iface)
168 {
169 FIXME("iface %p stub!\n", iface);
170
171 return E_NOTIMPL;
172 }
173
174 static const struct IDXGISurfaceVtbl dxgi_surface_vtbl =
175 {
176 /* IUnknown methods */
177 dxgi_surface_QueryInterface,
178 dxgi_surface_AddRef,
179 dxgi_surface_Release,
180 /* IDXGIObject methods */
181 dxgi_surface_SetPrivateData,
182 dxgi_surface_SetPrivateDataInterface,
183 dxgi_surface_GetPrivateData,
184 dxgi_surface_GetParent,
185 /* IDXGIDeviceSubObject methods */
186 dxgi_surface_GetDevice,
187 /* IDXGISurface methods */
188 dxgi_surface_GetDesc,
189 dxgi_surface_Map,
190 dxgi_surface_Unmap,
191 };
192
193 static const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl =
194 {
195 /* IUnknown methods */
196 dxgi_surface_inner_QueryInterface,
197 dxgi_surface_inner_AddRef,
198 dxgi_surface_inner_Release,
199 };
200
201 HRESULT dxgi_surface_init(struct dxgi_surface *surface, IDXGIDevice *device, IUnknown *outer)
202 {
203 surface->IDXGISurface_iface.lpVtbl = &dxgi_surface_vtbl;
204 surface->IUnknown_iface.lpVtbl = &dxgi_surface_inner_unknown_vtbl;
205 surface->refcount = 1;
206 surface->outer_unknown = outer ? outer : &surface->IUnknown_iface;
207 surface->device = device;
208 IDXGIDevice_AddRef(device);
209
210 return S_OK;
211 }