tools: Add support for generating cursor files from SVG.
[wine.git] / dlls / dxgi / surface.c
blob36fc1e60883040672241f704f8110928523cf680
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_IDXGISurface1)
41 || IsEqualGUID(riid, &IID_IDXGISurface)
42 || IsEqualGUID(riid, &IID_IDXGIDeviceSubObject)
43 || IsEqualGUID(riid, &IID_IDXGIObject)
44 || IsEqualGUID(riid, &IID_IUnknown))
46 IDXGISurface1_AddRef(&surface->IDXGISurface1_iface);
47 *out = &surface->IDXGISurface1_iface;
48 return S_OK;
51 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
53 *out = NULL;
54 return E_NOINTERFACE;
57 static ULONG STDMETHODCALLTYPE dxgi_surface_inner_AddRef(IUnknown *iface)
59 struct dxgi_surface *surface = impl_from_IUnknown(iface);
60 ULONG refcount = InterlockedIncrement(&surface->refcount);
62 TRACE("%p increasing refcount to %u.\n", surface, refcount);
64 return refcount;
67 static ULONG STDMETHODCALLTYPE dxgi_surface_inner_Release(IUnknown *iface)
69 struct dxgi_surface *surface = impl_from_IUnknown(iface);
70 ULONG refcount = InterlockedDecrement(&surface->refcount);
72 TRACE("%p decreasing refcount to %u.\n", surface, refcount);
74 if (!refcount)
76 wined3d_private_store_cleanup(&surface->private_store);
77 HeapFree(GetProcessHeap(), 0, surface);
80 return refcount;
83 static inline struct dxgi_surface *impl_from_IDXGISurface1(IDXGISurface1 *iface)
85 return CONTAINING_RECORD(iface, struct dxgi_surface, IDXGISurface1_iface);
88 /* IUnknown methods */
90 static HRESULT STDMETHODCALLTYPE dxgi_surface_QueryInterface(IDXGISurface1 *iface, REFIID riid,
91 void **object)
93 struct dxgi_surface *This = impl_from_IDXGISurface1(iface);
94 TRACE("Forwarding to outer IUnknown\n");
95 return IUnknown_QueryInterface(This->outer_unknown, riid, object);
98 static ULONG STDMETHODCALLTYPE dxgi_surface_AddRef(IDXGISurface1 *iface)
100 struct dxgi_surface *This = impl_from_IDXGISurface1(iface);
101 TRACE("Forwarding to outer IUnknown\n");
102 return IUnknown_AddRef(This->outer_unknown);
105 static ULONG STDMETHODCALLTYPE dxgi_surface_Release(IDXGISurface1 *iface)
107 struct dxgi_surface *This = impl_from_IDXGISurface1(iface);
108 TRACE("Forwarding to outer IUnknown\n");
109 return IUnknown_Release(This->outer_unknown);
112 /* IDXGIObject methods */
114 static HRESULT STDMETHODCALLTYPE dxgi_surface_SetPrivateData(IDXGISurface1 *iface,
115 REFGUID guid, UINT data_size, const void *data)
117 struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
119 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
121 return dxgi_set_private_data(&surface->private_store, guid, data_size, data);
124 static HRESULT STDMETHODCALLTYPE dxgi_surface_SetPrivateDataInterface(IDXGISurface1 *iface,
125 REFGUID guid, const IUnknown *object)
127 struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
129 TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);
131 return dxgi_set_private_data_interface(&surface->private_store, guid, object);
134 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetPrivateData(IDXGISurface1 *iface,
135 REFGUID guid, UINT *data_size, void *data)
137 struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
139 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
141 return dxgi_get_private_data(&surface->private_store, guid, data_size, data);
144 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetParent(IDXGISurface1 *iface, REFIID riid, void **parent)
146 struct dxgi_surface *This = impl_from_IDXGISurface1(iface);
148 TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
150 return IDXGIDevice_QueryInterface(This->device, riid, parent);
153 /* IDXGIDeviceSubObject methods */
155 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDevice(IDXGISurface1 *iface, REFIID riid, void **device)
157 struct dxgi_surface *This = impl_from_IDXGISurface1(iface);
159 TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device);
161 return IDXGIDevice_QueryInterface(This->device, riid, device);
164 /* IDXGISurface methods */
165 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDesc(IDXGISurface1 *iface, DXGI_SURFACE_DESC *desc)
167 struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
168 struct wined3d_resource_desc wined3d_desc;
170 TRACE("iface %p, desc %p.\n", iface, desc);
172 wined3d_mutex_lock();
173 wined3d_resource_get_desc(wined3d_texture_get_resource(surface->wined3d_texture), &wined3d_desc);
174 wined3d_mutex_unlock();
175 desc->Width = wined3d_desc.width;
176 desc->Height = wined3d_desc.height;
177 desc->Format = dxgi_format_from_wined3dformat(wined3d_desc.format);
178 dxgi_sample_desc_from_wined3d(&desc->SampleDesc, wined3d_desc.multisample_type, wined3d_desc.multisample_quality);
180 return S_OK;
183 static HRESULT STDMETHODCALLTYPE dxgi_surface_Map(IDXGISurface1 *iface, DXGI_MAPPED_RECT *mapped_rect, UINT flags)
185 FIXME("iface %p, mapped_rect %p, flags %#x stub!\n", iface, mapped_rect, flags);
187 return E_NOTIMPL;
190 static HRESULT STDMETHODCALLTYPE dxgi_surface_Unmap(IDXGISurface1 *iface)
192 FIXME("iface %p stub!\n", iface);
194 return E_NOTIMPL;
197 /* IDXGISurface1 methods */
198 static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDC(IDXGISurface1 *iface, BOOL discard, HDC *hdc)
200 struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
201 HRESULT hr;
203 FIXME("iface %p, discard %d, hdc %p semi-stub!\n", iface, discard, hdc);
205 if (!hdc)
206 return E_INVALIDARG;
208 wined3d_mutex_lock();
209 hr = wined3d_texture_get_dc(surface->wined3d_texture, 0, hdc);
210 wined3d_mutex_unlock();
212 if (SUCCEEDED(hr))
213 surface->dc = *hdc;
215 return hr;
218 static HRESULT STDMETHODCALLTYPE dxgi_surface_ReleaseDC(IDXGISurface1 *iface, RECT *dirty_rect)
220 struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
221 HRESULT hr;
223 TRACE("iface %p, rect %s\n", iface, wine_dbgstr_rect(dirty_rect));
225 if (!IsRectEmpty(dirty_rect))
226 FIXME("dirty rectangle is ignored.\n");
228 wined3d_mutex_lock();
229 hr = wined3d_texture_release_dc(surface->wined3d_texture, 0, surface->dc);
230 wined3d_mutex_unlock();
232 return hr;
235 static const struct IDXGISurface1Vtbl dxgi_surface_vtbl =
237 /* IUnknown methods */
238 dxgi_surface_QueryInterface,
239 dxgi_surface_AddRef,
240 dxgi_surface_Release,
241 /* IDXGIObject methods */
242 dxgi_surface_SetPrivateData,
243 dxgi_surface_SetPrivateDataInterface,
244 dxgi_surface_GetPrivateData,
245 dxgi_surface_GetParent,
246 /* IDXGIDeviceSubObject methods */
247 dxgi_surface_GetDevice,
248 /* IDXGISurface methods */
249 dxgi_surface_GetDesc,
250 dxgi_surface_Map,
251 dxgi_surface_Unmap,
252 /* IDXGISurface1 methods */
253 dxgi_surface_GetDC,
254 dxgi_surface_ReleaseDC,
257 static const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl =
259 /* IUnknown methods */
260 dxgi_surface_inner_QueryInterface,
261 dxgi_surface_inner_AddRef,
262 dxgi_surface_inner_Release,
265 HRESULT dxgi_surface_init(struct dxgi_surface *surface, IDXGIDevice *device,
266 IUnknown *outer, struct wined3d_texture *wined3d_texture)
268 surface->IDXGISurface1_iface.lpVtbl = &dxgi_surface_vtbl;
269 surface->IUnknown_iface.lpVtbl = &dxgi_surface_inner_unknown_vtbl;
270 surface->refcount = 1;
271 wined3d_private_store_init(&surface->private_store);
272 surface->outer_unknown = outer ? outer : &surface->IUnknown_iface;
273 surface->device = device;
274 surface->wined3d_texture = wined3d_texture;
275 surface->dc = NULL;
277 return S_OK;