2 * Copyright 2008 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 static inline struct dxgi_swapchain
*impl_from_IDXGISwapChain(IDXGISwapChain
*iface
)
29 return CONTAINING_RECORD(iface
, struct dxgi_swapchain
, IDXGISwapChain_iface
);
32 /* IUnknown methods */
34 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_QueryInterface(IDXGISwapChain
*iface
, REFIID riid
, void **object
)
36 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
38 if (IsEqualGUID(riid
, &IID_IUnknown
)
39 || IsEqualGUID(riid
, &IID_IDXGIObject
)
40 || IsEqualGUID(riid
, &IID_IDXGIDeviceSubObject
)
41 || IsEqualGUID(riid
, &IID_IDXGISwapChain
))
43 IUnknown_AddRef(iface
);
48 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
54 static ULONG STDMETHODCALLTYPE
dxgi_swapchain_AddRef(IDXGISwapChain
*iface
)
56 struct dxgi_swapchain
*This
= impl_from_IDXGISwapChain(iface
);
57 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
59 TRACE("%p increasing refcount to %u\n", This
, refcount
);
62 wined3d_swapchain_incref(This
->wined3d_swapchain
);
67 static ULONG STDMETHODCALLTYPE
dxgi_swapchain_Release(IDXGISwapChain
*iface
)
69 struct dxgi_swapchain
*This
= impl_from_IDXGISwapChain(iface
);
70 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
72 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
76 struct wined3d_device
*wined3d_device
;
79 FIXME("Only a single swapchain is supported\n");
81 wined3d_device
= wined3d_swapchain_get_device(This
->wined3d_swapchain
);
82 hr
= wined3d_device_uninit_3d(wined3d_device
);
85 ERR("Uninit3D failed, hr %#x\n", hr
);
92 /* IDXGIObject methods */
94 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_SetPrivateData(IDXGISwapChain
*iface
,
95 REFGUID guid
, UINT data_size
, const void *data
)
97 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface
, debugstr_guid(guid
), data_size
, data
);
102 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_SetPrivateDataInterface(IDXGISwapChain
*iface
,
103 REFGUID guid
, const IUnknown
*object
)
105 FIXME("iface %p, guid %s, object %p stub!\n", iface
, debugstr_guid(guid
), object
);
110 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetPrivateData(IDXGISwapChain
*iface
,
111 REFGUID guid
, UINT
*data_size
, void *data
)
113 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface
, debugstr_guid(guid
), data_size
, data
);
118 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetParent(IDXGISwapChain
*iface
, REFIID riid
, void **parent
)
120 FIXME("iface %p, riid %s, parent %p stub!\n", iface
, debugstr_guid(riid
), parent
);
125 /* IDXGIDeviceSubObject methods */
127 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetDevice(IDXGISwapChain
*iface
, REFIID riid
, void **device
)
129 FIXME("iface %p, riid %s, device %p stub!\n", iface
, debugstr_guid(riid
), device
);
134 /* IDXGISwapChain methods */
136 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_Present(IDXGISwapChain
*iface
, UINT sync_interval
, UINT flags
)
138 struct dxgi_swapchain
*This
= impl_from_IDXGISwapChain(iface
);
140 TRACE("iface %p, sync_interval %u, flags %#x\n", iface
, sync_interval
, flags
);
142 if (sync_interval
) FIXME("Unimplemented sync interval %u\n", sync_interval
);
143 if (flags
) FIXME("Unimplemented flags %#x\n", flags
);
145 return wined3d_swapchain_present(This
->wined3d_swapchain
, NULL
, NULL
, NULL
, NULL
, 0);
148 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetBuffer(IDXGISwapChain
*iface
,
149 UINT buffer_idx
, REFIID riid
, void **surface
)
151 struct dxgi_swapchain
*This
= impl_from_IDXGISwapChain(iface
);
152 struct wined3d_surface
*backbuffer
;
156 TRACE("iface %p, buffer_idx %u, riid %s, surface %p\n",
157 iface
, buffer_idx
, debugstr_guid(riid
), surface
);
159 EnterCriticalSection(&dxgi_cs
);
161 hr
= wined3d_swapchain_get_back_buffer(This
->wined3d_swapchain
,
162 buffer_idx
, WINED3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
165 LeaveCriticalSection(&dxgi_cs
);
169 parent
= wined3d_surface_get_parent(backbuffer
);
170 hr
= IUnknown_QueryInterface(parent
, riid
, surface
);
171 wined3d_surface_decref(backbuffer
);
172 LeaveCriticalSection(&dxgi_cs
);
177 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_SetFullscreenState(IDXGISwapChain
*iface
,
178 BOOL fullscreen
, IDXGIOutput
*target
)
180 FIXME("iface %p, fullscreen %u, target %p stub!\n", iface
, fullscreen
, target
);
185 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetFullscreenState(IDXGISwapChain
*iface
,
186 BOOL
*fullscreen
, IDXGIOutput
**target
)
188 FIXME("iface %p, fullscreen %p, target %p stub!\n", iface
, fullscreen
, target
);
193 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetDesc(IDXGISwapChain
*iface
, DXGI_SWAP_CHAIN_DESC
*desc
)
195 FIXME("iface %p, desc %p stub!\n", iface
, desc
);
200 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_ResizeBuffers(IDXGISwapChain
*iface
,
201 UINT buffer_count
, UINT width
, UINT height
, DXGI_FORMAT format
, UINT flags
)
203 FIXME("iface %p, buffer_count %u, width %u, height %u, format %s, flags %#x stub!\n",
204 iface
, buffer_count
, width
, height
, debug_dxgi_format(format
), flags
);
209 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_ResizeTarget(IDXGISwapChain
*iface
,
210 const DXGI_MODE_DESC
*target_mode_desc
)
212 FIXME("iface %p, target_mode_desc %p stub!\n", iface
, target_mode_desc
);
217 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetContainingOutput(IDXGISwapChain
*iface
, IDXGIOutput
**output
)
219 FIXME("iface %p, output %p stub!\n", iface
, output
);
224 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetFrameStatistics(IDXGISwapChain
*iface
, DXGI_FRAME_STATISTICS
*stats
)
226 FIXME("iface %p, stats %p stub!\n", iface
, stats
);
231 static HRESULT STDMETHODCALLTYPE
dxgi_swapchain_GetLastPresentCount(IDXGISwapChain
*iface
, UINT
*last_present_count
)
233 FIXME("iface %p, last_present_count %p stub!\n", iface
, last_present_count
);
238 static const struct IDXGISwapChainVtbl dxgi_swapchain_vtbl
=
240 /* IUnknown methods */
241 dxgi_swapchain_QueryInterface
,
242 dxgi_swapchain_AddRef
,
243 dxgi_swapchain_Release
,
244 /* IDXGIObject methods */
245 dxgi_swapchain_SetPrivateData
,
246 dxgi_swapchain_SetPrivateDataInterface
,
247 dxgi_swapchain_GetPrivateData
,
248 dxgi_swapchain_GetParent
,
249 /* IDXGIDeviceSubObject methods */
250 dxgi_swapchain_GetDevice
,
251 /* IDXGISwapChain methods */
252 dxgi_swapchain_Present
,
253 dxgi_swapchain_GetBuffer
,
254 dxgi_swapchain_SetFullscreenState
,
255 dxgi_swapchain_GetFullscreenState
,
256 dxgi_swapchain_GetDesc
,
257 dxgi_swapchain_ResizeBuffers
,
258 dxgi_swapchain_ResizeTarget
,
259 dxgi_swapchain_GetContainingOutput
,
260 dxgi_swapchain_GetFrameStatistics
,
261 dxgi_swapchain_GetLastPresentCount
,
264 static void STDMETHODCALLTYPE
dxgi_swapchain_wined3d_object_released(void *parent
)
266 HeapFree(GetProcessHeap(), 0, parent
);
269 static const struct wined3d_parent_ops dxgi_swapchain_wined3d_parent_ops
=
271 dxgi_swapchain_wined3d_object_released
,
274 HRESULT
dxgi_swapchain_init(struct dxgi_swapchain
*swapchain
, struct dxgi_device
*device
,
275 WINED3DPRESENT_PARAMETERS
*present_parameters
)
279 swapchain
->IDXGISwapChain_iface
.lpVtbl
= &dxgi_swapchain_vtbl
;
280 swapchain
->refcount
= 1;
282 hr
= wined3d_swapchain_create(device
->wined3d_device
, present_parameters
,
283 SURFACE_OPENGL
, swapchain
, &dxgi_swapchain_wined3d_parent_ops
,
284 &swapchain
->wined3d_swapchain
);
287 WARN("Failed to create wined3d swapchain, hr %#x.\n", hr
);