winex11: Add window data structure locking to the GravityNotify event handler.
[wine.git] / dlls / dxgi / surface.c
blobf7fa93176cedad02bbf1fcc7b32ffdba7d0a1eba
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 #include "dxgi_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
27 /* Inner IUnknown methods */
29 static inline struct dxgi_surface *impl_from_IUnknown(IUnknown *iface)
31 return CONTAINING_RECORD(iface, struct dxgi_surface, IUnknown_iface);
34 static HRESULT STDMETHODCALLTYPE dxgi_surface_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
36 struct dxgi_surface *surface = impl_from_IUnknown(iface);
38 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
40 if (IsEqualGUID(riid, &IID_IDXGISurface)
41 || IsEqualGUID(riid, &IID_IDXGIDeviceSubObject)
42 || IsEqualGUID(riid, &IID_IDXGIObject)
43 || IsEqualGUID(riid, &IID_IUnknown))
45 IDXGISurface_AddRef(&surface->IDXGISurface_iface);
46 *out = &surface->IDXGISurface_iface;
47 return S_OK;
50 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
52 *out = NULL;
53 return E_NOINTERFACE;
56 static ULONG STDMETHODCALLTYPE dxgi_surface_inner_AddRef(IUnknown *iface)
58 struct dxgi_surface *surface = impl_from_IUnknown(iface);
59 ULONG refcount = InterlockedIncrement(&surface->refcount);
61 TRACE("%p increasing refcount to %u.\n", surface, refcount);
63 return refcount;
66 static ULONG STDMETHODCALLTYPE dxgi_surface_inner_Release(IUnknown *iface)
68 struct dxgi_surface *surface = impl_from_IUnknown(iface);
69 ULONG refcount = InterlockedDecrement(&surface->refcount);
71 TRACE("%p decreasing refcount to %u.\n", surface, refcount);
73 if (!refcount)
75 IDXGIDevice_Release(surface->device);
76 HeapFree(GetProcessHeap(), 0, surface);
79 return refcount;
82 static inline struct dxgi_surface *impl_from_IDXGISurface(IDXGISurface *iface)
84 return CONTAINING_RECORD(iface, struct dxgi_surface, IDXGISurface_iface);
87 /* IUnknown methods */
89 static HRESULT STDMETHODCALLTYPE dxgi_surface_QueryInterface(IDXGISurface *iface, REFIID riid,
90 void **object)
92 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
93 TRACE("Forwarding to outer IUnknown\n");
94 return IUnknown_QueryInterface(This->outer_unknown, riid, object);
97 static ULONG STDMETHODCALLTYPE dxgi_surface_AddRef(IDXGISurface *iface)
99 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
100 TRACE("Forwarding to outer IUnknown\n");
101 return IUnknown_AddRef(This->outer_unknown);
104 static ULONG STDMETHODCALLTYPE dxgi_surface_Release(IDXGISurface *iface)
106 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
107 TRACE("Forwarding to outer IUnknown\n");
108 return IUnknown_Release(This->outer_unknown);
111 /* IDXGIObject methods */
113 static HRESULT STDMETHODCALLTYPE dxgi_surface_SetPrivateData(IDXGISurface *iface,
114 REFGUID guid, UINT data_size, const void *data)
116 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
118 return E_NOTIMPL;
121 static HRESULT STDMETHODCALLTYPE dxgi_surface_SetPrivateDataInterface(IDXGISurface *iface,
122 REFGUID guid, const IUnknown *object)
124 FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
126 return E_NOTIMPL;
129 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetPrivateData(IDXGISurface *iface,
130 REFGUID guid, UINT *data_size, void *data)
132 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
134 return E_NOTIMPL;
137 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetParent(IDXGISurface *iface, REFIID riid, void **parent)
139 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
141 TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
143 return IDXGIDevice_QueryInterface(This->device, riid, parent);
146 /* IDXGIDeviceSubObject methods */
148 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDevice(IDXGISurface *iface, REFIID riid, void **device)
150 struct dxgi_surface *This = impl_from_IDXGISurface(iface);
152 TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device);
154 return IDXGIDevice_QueryInterface(This->device, riid, device);
157 /* IDXGISurface methods */
158 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDesc(IDXGISurface *iface, DXGI_SURFACE_DESC *desc)
160 FIXME("iface %p, desc %p stub!\n", iface, desc);
162 return E_NOTIMPL;
165 static HRESULT STDMETHODCALLTYPE dxgi_surface_Map(IDXGISurface *iface, DXGI_MAPPED_RECT *mapped_rect, UINT flags)
167 FIXME("iface %p, mapped_rect %p, flags %#x stub!\n", iface, mapped_rect, flags);
169 return E_NOTIMPL;
172 static HRESULT STDMETHODCALLTYPE dxgi_surface_Unmap(IDXGISurface *iface)
174 FIXME("iface %p stub!\n", iface);
176 return E_NOTIMPL;
179 static const struct IDXGISurfaceVtbl dxgi_surface_vtbl =
181 /* IUnknown methods */
182 dxgi_surface_QueryInterface,
183 dxgi_surface_AddRef,
184 dxgi_surface_Release,
185 /* IDXGIObject methods */
186 dxgi_surface_SetPrivateData,
187 dxgi_surface_SetPrivateDataInterface,
188 dxgi_surface_GetPrivateData,
189 dxgi_surface_GetParent,
190 /* IDXGIDeviceSubObject methods */
191 dxgi_surface_GetDevice,
192 /* IDXGISurface methods */
193 dxgi_surface_GetDesc,
194 dxgi_surface_Map,
195 dxgi_surface_Unmap,
198 static const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl =
200 /* IUnknown methods */
201 dxgi_surface_inner_QueryInterface,
202 dxgi_surface_inner_AddRef,
203 dxgi_surface_inner_Release,
206 HRESULT dxgi_surface_init(struct dxgi_surface *surface, IDXGIDevice *device, IUnknown *outer)
208 surface->IDXGISurface_iface.lpVtbl = &dxgi_surface_vtbl;
209 surface->IUnknown_iface.lpVtbl = &dxgi_surface_inner_unknown_vtbl;
210 surface->refcount = 1;
211 surface->outer_unknown = outer ? outer : &surface->IUnknown_iface;
212 surface->device = device;
213 IDXGIDevice_AddRef(device);
215 return S_OK;