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
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
;
51 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
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
);
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
);
76 wined3d_private_store_cleanup(&surface
->private_store
);
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
,
93 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
94 TRACE("Forwarding to outer IUnknown\n");
95 return IUnknown_QueryInterface(surface
->outer_unknown
, riid
, object
);
98 static ULONG STDMETHODCALLTYPE
dxgi_surface_AddRef(IDXGISurface1
*iface
)
100 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
101 TRACE("Forwarding to outer IUnknown\n");
102 return IUnknown_AddRef(surface
->outer_unknown
);
105 static ULONG STDMETHODCALLTYPE
dxgi_surface_Release(IDXGISurface1
*iface
)
107 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
108 TRACE("Forwarding to outer IUnknown\n");
109 return IUnknown_Release(surface
->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
*surface
= impl_from_IDXGISurface1(iface
);
148 TRACE("iface %p, riid %s, parent %p.\n", iface
, debugstr_guid(riid
), parent
);
150 return IDXGIDevice_QueryInterface(surface
->device
, riid
, parent
);
153 /* IDXGIDeviceSubObject methods */
155 static HRESULT STDMETHODCALLTYPE
dxgi_surface_GetDevice(IDXGISurface1
*iface
, REFIID riid
, void **device
)
157 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
159 TRACE("iface %p, riid %s, device %p.\n", iface
, debugstr_guid(riid
), device
);
161 return IDXGIDevice_QueryInterface(surface
->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
);
183 static HRESULT STDMETHODCALLTYPE
dxgi_surface_Map(IDXGISurface1
*iface
, DXGI_MAPPED_RECT
*mapped_rect
, UINT flags
)
185 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
186 struct wined3d_map_desc wined3d_map_desc
;
187 DWORD wined3d_map_flags
= 0;
190 TRACE("iface %p, mapped_rect %p, flags %#x.\n", iface
, mapped_rect
, flags
);
192 if (flags
& DXGI_MAP_READ
)
193 wined3d_map_flags
|= WINED3D_MAP_READ
;
194 if (flags
& DXGI_MAP_WRITE
)
195 wined3d_map_flags
|= WINED3D_MAP_WRITE
;
196 if (flags
& DXGI_MAP_DISCARD
)
197 wined3d_map_flags
|= WINED3D_MAP_DISCARD
;
199 wined3d_mutex_lock();
200 if (SUCCEEDED(hr
= wined3d_resource_map(wined3d_texture_get_resource(surface
->wined3d_texture
), 0,
201 &wined3d_map_desc
, NULL
, wined3d_map_flags
)))
203 mapped_rect
->Pitch
= wined3d_map_desc
.row_pitch
;
204 mapped_rect
->pBits
= wined3d_map_desc
.data
;
206 wined3d_mutex_unlock();
211 static HRESULT STDMETHODCALLTYPE
dxgi_surface_Unmap(IDXGISurface1
*iface
)
213 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
215 TRACE("iface %p.\n", iface
);
217 wined3d_mutex_lock();
218 wined3d_resource_unmap(wined3d_texture_get_resource(surface
->wined3d_texture
), 0);
219 wined3d_mutex_unlock();
224 /* IDXGISurface1 methods */
225 static HRESULT STDMETHODCALLTYPE
dxgi_surface_GetDC(IDXGISurface1
*iface
, BOOL discard
, HDC
*hdc
)
227 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
230 FIXME("iface %p, discard %d, hdc %p semi-stub!\n", iface
, discard
, hdc
);
235 wined3d_mutex_lock();
236 hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, 0, hdc
);
237 wined3d_mutex_unlock();
245 static HRESULT STDMETHODCALLTYPE
dxgi_surface_ReleaseDC(IDXGISurface1
*iface
, RECT
*dirty_rect
)
247 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
250 TRACE("iface %p, rect %s\n", iface
, wine_dbgstr_rect(dirty_rect
));
252 if (!IsRectEmpty(dirty_rect
))
253 FIXME("dirty rectangle is ignored.\n");
255 wined3d_mutex_lock();
256 hr
= wined3d_texture_release_dc(surface
->wined3d_texture
, 0, surface
->dc
);
257 wined3d_mutex_unlock();
262 static const struct IDXGISurface1Vtbl dxgi_surface_vtbl
=
264 /* IUnknown methods */
265 dxgi_surface_QueryInterface
,
267 dxgi_surface_Release
,
268 /* IDXGIObject methods */
269 dxgi_surface_SetPrivateData
,
270 dxgi_surface_SetPrivateDataInterface
,
271 dxgi_surface_GetPrivateData
,
272 dxgi_surface_GetParent
,
273 /* IDXGIDeviceSubObject methods */
274 dxgi_surface_GetDevice
,
275 /* IDXGISurface methods */
276 dxgi_surface_GetDesc
,
279 /* IDXGISurface1 methods */
281 dxgi_surface_ReleaseDC
,
284 static const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl
=
286 /* IUnknown methods */
287 dxgi_surface_inner_QueryInterface
,
288 dxgi_surface_inner_AddRef
,
289 dxgi_surface_inner_Release
,
292 HRESULT
dxgi_surface_init(struct dxgi_surface
*surface
, IDXGIDevice
*device
,
293 IUnknown
*outer
, struct wined3d_texture
*wined3d_texture
)
295 surface
->IDXGISurface1_iface
.lpVtbl
= &dxgi_surface_vtbl
;
296 surface
->IUnknown_iface
.lpVtbl
= &dxgi_surface_inner_unknown_vtbl
;
297 surface
->refcount
= 1;
298 wined3d_private_store_init(&surface
->private_store
);
299 surface
->outer_unknown
= outer
? outer
: &surface
->IUnknown_iface
;
300 surface
->device
= device
;
301 surface
->wined3d_texture
= wined3d_texture
;