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
22 #include "dxgi_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(dxgi
);
26 /* Inner IUnknown methods */
28 static inline struct dxgi_surface
*impl_from_IUnknown(IUnknown
*iface
)
30 return CONTAINING_RECORD(iface
, struct dxgi_surface
, IUnknown_iface
);
33 static HRESULT STDMETHODCALLTYPE
dxgi_surface_inner_QueryInterface(IUnknown
*iface
, REFIID riid
, void **out
)
35 struct dxgi_surface
*surface
= impl_from_IUnknown(iface
);
37 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
39 if (IsEqualGUID(riid
, &IID_IDXGISurface1
)
40 || IsEqualGUID(riid
, &IID_IDXGISurface
)
41 || IsEqualGUID(riid
, &IID_IDXGIDeviceSubObject
)
42 || IsEqualGUID(riid
, &IID_IDXGIObject
)
43 || IsEqualGUID(riid
, &IID_IUnknown
))
45 IDXGISurface1_AddRef(&surface
->IDXGISurface1_iface
);
46 *out
= &surface
->IDXGISurface1_iface
;
50 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
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
);
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
);
75 wined3d_private_store_cleanup(&surface
->private_store
);
82 static inline struct dxgi_surface
*impl_from_IDXGISurface1(IDXGISurface1
*iface
)
84 return CONTAINING_RECORD(iface
, struct dxgi_surface
, IDXGISurface1_iface
);
87 /* IUnknown methods */
89 static HRESULT STDMETHODCALLTYPE
dxgi_surface_QueryInterface(IDXGISurface1
*iface
, REFIID riid
,
92 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
93 TRACE("Forwarding to outer IUnknown\n");
94 return IUnknown_QueryInterface(surface
->outer_unknown
, riid
, object
);
97 static ULONG STDMETHODCALLTYPE
dxgi_surface_AddRef(IDXGISurface1
*iface
)
99 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
100 TRACE("Forwarding to outer IUnknown\n");
101 return IUnknown_AddRef(surface
->outer_unknown
);
104 static ULONG STDMETHODCALLTYPE
dxgi_surface_Release(IDXGISurface1
*iface
)
106 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
107 TRACE("Forwarding to outer IUnknown\n");
108 return IUnknown_Release(surface
->outer_unknown
);
111 /* IDXGIObject methods */
113 static HRESULT STDMETHODCALLTYPE
dxgi_surface_SetPrivateData(IDXGISurface1
*iface
,
114 REFGUID guid
, UINT data_size
, const void *data
)
116 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
118 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
120 return dxgi_set_private_data(&surface
->private_store
, guid
, data_size
, data
);
123 static HRESULT STDMETHODCALLTYPE
dxgi_surface_SetPrivateDataInterface(IDXGISurface1
*iface
,
124 REFGUID guid
, const IUnknown
*object
)
126 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
128 TRACE("iface %p, guid %s, object %p.\n", iface
, debugstr_guid(guid
), object
);
130 return dxgi_set_private_data_interface(&surface
->private_store
, guid
, object
);
133 static HRESULT STDMETHODCALLTYPE
dxgi_surface_GetPrivateData(IDXGISurface1
*iface
,
134 REFGUID guid
, UINT
*data_size
, void *data
)
136 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
138 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
140 return dxgi_get_private_data(&surface
->private_store
, guid
, data_size
, data
);
143 static HRESULT STDMETHODCALLTYPE
dxgi_surface_GetParent(IDXGISurface1
*iface
, REFIID riid
, void **parent
)
145 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
147 TRACE("iface %p, riid %s, parent %p.\n", iface
, debugstr_guid(riid
), parent
);
149 return IDXGIDevice_QueryInterface(surface
->device
, riid
, parent
);
152 /* IDXGIDeviceSubObject methods */
154 static HRESULT STDMETHODCALLTYPE
dxgi_surface_GetDevice(IDXGISurface1
*iface
, REFIID riid
, void **device
)
156 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
158 TRACE("iface %p, riid %s, device %p.\n", iface
, debugstr_guid(riid
), device
);
160 return IDXGIDevice_QueryInterface(surface
->device
, riid
, device
);
163 /* IDXGISurface methods */
164 static HRESULT STDMETHODCALLTYPE
dxgi_surface_GetDesc(IDXGISurface1
*iface
, DXGI_SURFACE_DESC
*desc
)
166 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
167 struct wined3d_resource_desc wined3d_desc
;
169 TRACE("iface %p, desc %p.\n", iface
, desc
);
171 wined3d_mutex_lock();
172 wined3d_resource_get_desc(wined3d_texture_get_resource(surface
->wined3d_texture
), &wined3d_desc
);
173 wined3d_mutex_unlock();
174 desc
->Width
= wined3d_desc
.width
;
175 desc
->Height
= wined3d_desc
.height
;
176 desc
->Format
= dxgi_format_from_wined3dformat(wined3d_desc
.format
);
177 dxgi_sample_desc_from_wined3d(&desc
->SampleDesc
, wined3d_desc
.multisample_type
, wined3d_desc
.multisample_quality
);
182 static HRESULT STDMETHODCALLTYPE
dxgi_surface_Map(IDXGISurface1
*iface
, DXGI_MAPPED_RECT
*mapped_rect
, UINT flags
)
184 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
185 struct wined3d_map_desc wined3d_map_desc
;
186 DWORD wined3d_map_flags
= 0;
189 TRACE("iface %p, mapped_rect %p, flags %#x.\n", iface
, mapped_rect
, flags
);
191 if (flags
& DXGI_MAP_READ
)
192 wined3d_map_flags
|= WINED3D_MAP_READ
;
193 if (flags
& DXGI_MAP_WRITE
)
194 wined3d_map_flags
|= WINED3D_MAP_WRITE
;
195 if (flags
& DXGI_MAP_DISCARD
)
196 wined3d_map_flags
|= WINED3D_MAP_DISCARD
;
198 if (SUCCEEDED(hr
= wined3d_resource_map(wined3d_texture_get_resource(surface
->wined3d_texture
), 0,
199 &wined3d_map_desc
, NULL
, wined3d_map_flags
)))
201 mapped_rect
->Pitch
= wined3d_map_desc
.row_pitch
;
202 mapped_rect
->pBits
= wined3d_map_desc
.data
;
208 static HRESULT STDMETHODCALLTYPE
dxgi_surface_Unmap(IDXGISurface1
*iface
)
210 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
212 TRACE("iface %p.\n", iface
);
213 wined3d_resource_unmap(wined3d_texture_get_resource(surface
->wined3d_texture
), 0);
217 /* IDXGISurface1 methods */
218 static HRESULT STDMETHODCALLTYPE
dxgi_surface_GetDC(IDXGISurface1
*iface
, BOOL discard
, HDC
*hdc
)
220 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
223 FIXME("iface %p, discard %d, hdc %p semi-stub!\n", iface
, discard
, hdc
);
228 wined3d_mutex_lock();
229 hr
= wined3d_texture_get_dc(surface
->wined3d_texture
, 0, hdc
);
230 wined3d_mutex_unlock();
238 static HRESULT STDMETHODCALLTYPE
dxgi_surface_ReleaseDC(IDXGISurface1
*iface
, RECT
*dirty_rect
)
240 struct dxgi_surface
*surface
= impl_from_IDXGISurface1(iface
);
243 TRACE("iface %p, rect %s\n", iface
, wine_dbgstr_rect(dirty_rect
));
245 if (!IsRectEmpty(dirty_rect
))
246 FIXME("dirty rectangle is ignored.\n");
248 wined3d_mutex_lock();
249 hr
= wined3d_texture_release_dc(surface
->wined3d_texture
, 0, surface
->dc
);
250 wined3d_mutex_unlock();
255 static const struct IDXGISurface1Vtbl dxgi_surface_vtbl
=
257 /* IUnknown methods */
258 dxgi_surface_QueryInterface
,
260 dxgi_surface_Release
,
261 /* IDXGIObject methods */
262 dxgi_surface_SetPrivateData
,
263 dxgi_surface_SetPrivateDataInterface
,
264 dxgi_surface_GetPrivateData
,
265 dxgi_surface_GetParent
,
266 /* IDXGIDeviceSubObject methods */
267 dxgi_surface_GetDevice
,
268 /* IDXGISurface methods */
269 dxgi_surface_GetDesc
,
272 /* IDXGISurface1 methods */
274 dxgi_surface_ReleaseDC
,
277 static const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl
=
279 /* IUnknown methods */
280 dxgi_surface_inner_QueryInterface
,
281 dxgi_surface_inner_AddRef
,
282 dxgi_surface_inner_Release
,
285 HRESULT
dxgi_surface_init(struct dxgi_surface
*surface
, IDXGIDevice
*device
,
286 IUnknown
*outer
, struct wined3d_texture
*wined3d_texture
)
288 surface
->IDXGISurface1_iface
.lpVtbl
= &dxgi_surface_vtbl
;
289 surface
->IUnknown_iface
.lpVtbl
= &dxgi_surface_inner_unknown_vtbl
;
290 surface
->refcount
= 1;
291 wined3d_private_store_init(&surface
->private_store
);
292 surface
->outer_unknown
= outer
? outer
: &surface
->IUnknown_iface
;
293 surface
->device
= device
;
294 surface
->wined3d_texture
= wined3d_texture
;