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
);
77 HeapFree(GetProcessHeap(), 0, surface
);
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
*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(surface
->wined3d_resource
, &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 FIXME("iface %p, mapped_rect %p, flags %#x stub!\n", iface
, mapped_rect
, flags
);
190 static HRESULT STDMETHODCALLTYPE
dxgi_surface_Unmap(IDXGISurface1
*iface
)
192 FIXME("iface %p stub!\n", iface
);
197 /* IDXGISurface1 methods */
198 static HRESULT STDMETHODCALLTYPE
dxgi_surface_GetDC(IDXGISurface1
*iface
, BOOL discard
, HDC
*hdc
)
200 FIXME("iface %p, discard %d, hdc %p stub!\n", iface
, discard
, hdc
);
205 static HRESULT STDMETHODCALLTYPE
dxgi_surface_ReleaseDC(IDXGISurface1
*iface
, RECT
*dirty_rect
)
207 FIXME("iface %p, rect %p stub!\n", iface
, dirty_rect
);
212 static const struct IDXGISurface1Vtbl dxgi_surface_vtbl
=
214 /* IUnknown methods */
215 dxgi_surface_QueryInterface
,
217 dxgi_surface_Release
,
218 /* IDXGIObject methods */
219 dxgi_surface_SetPrivateData
,
220 dxgi_surface_SetPrivateDataInterface
,
221 dxgi_surface_GetPrivateData
,
222 dxgi_surface_GetParent
,
223 /* IDXGIDeviceSubObject methods */
224 dxgi_surface_GetDevice
,
225 /* IDXGISurface methods */
226 dxgi_surface_GetDesc
,
229 /* IDXGISurface1 methods */
231 dxgi_surface_ReleaseDC
,
234 static const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl
=
236 /* IUnknown methods */
237 dxgi_surface_inner_QueryInterface
,
238 dxgi_surface_inner_AddRef
,
239 dxgi_surface_inner_Release
,
242 HRESULT
dxgi_surface_init(struct dxgi_surface
*surface
, IDXGIDevice
*device
,
243 IUnknown
*outer
, struct wined3d_resource
*wined3d_resource
)
245 surface
->IDXGISurface1_iface
.lpVtbl
= &dxgi_surface_vtbl
;
246 surface
->IUnknown_iface
.lpVtbl
= &dxgi_surface_inner_unknown_vtbl
;
247 surface
->refcount
= 1;
248 wined3d_private_store_init(&surface
->private_store
);
249 surface
->outer_unknown
= outer
? outer
: &surface
->IUnknown_iface
;
250 surface
->device
= device
;
251 surface
->wined3d_resource
= wined3d_resource
;