dxgi: Call wined3d_device_init_3d() on device creation.
[wine/multimedia.git] / dlls / dxgi / swapchain.c
blob437537a6b1f6a3716b482d04f7da779ab7dde51f
1 /*
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
20 #include "config.h"
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);
44 *object = iface;
45 return S_OK;
48 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
50 *object = NULL;
51 return E_NOINTERFACE;
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);
61 if (refcount == 1)
62 wined3d_swapchain_incref(This->wined3d_swapchain);
64 return refcount;
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);
74 if (!refcount)
75 wined3d_swapchain_decref(This->wined3d_swapchain);
77 return refcount;
80 /* IDXGIObject methods */
82 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetPrivateData(IDXGISwapChain *iface,
83 REFGUID guid, UINT data_size, const void *data)
85 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
87 return E_NOTIMPL;
90 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetPrivateDataInterface(IDXGISwapChain *iface,
91 REFGUID guid, const IUnknown *object)
93 FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
95 return E_NOTIMPL;
98 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetPrivateData(IDXGISwapChain *iface,
99 REFGUID guid, UINT *data_size, void *data)
101 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
103 return E_NOTIMPL;
106 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetParent(IDXGISwapChain *iface, REFIID riid, void **parent)
108 FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
110 return E_NOTIMPL;
113 /* IDXGIDeviceSubObject methods */
115 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetDevice(IDXGISwapChain *iface, REFIID riid, void **device)
117 FIXME("iface %p, riid %s, device %p stub!\n", iface, debugstr_guid(riid), device);
119 return E_NOTIMPL;
122 /* IDXGISwapChain methods */
124 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_Present(IDXGISwapChain *iface, UINT sync_interval, UINT flags)
126 struct dxgi_swapchain *This = impl_from_IDXGISwapChain(iface);
128 TRACE("iface %p, sync_interval %u, flags %#x\n", iface, sync_interval, flags);
130 if (sync_interval) FIXME("Unimplemented sync interval %u\n", sync_interval);
131 if (flags) FIXME("Unimplemented flags %#x\n", flags);
133 return wined3d_swapchain_present(This->wined3d_swapchain, NULL, NULL, NULL, NULL, 0);
136 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetBuffer(IDXGISwapChain *iface,
137 UINT buffer_idx, REFIID riid, void **surface)
139 struct dxgi_swapchain *This = impl_from_IDXGISwapChain(iface);
140 struct wined3d_surface *backbuffer;
141 IUnknown *parent;
142 HRESULT hr;
144 TRACE("iface %p, buffer_idx %u, riid %s, surface %p\n",
145 iface, buffer_idx, debugstr_guid(riid), surface);
147 EnterCriticalSection(&dxgi_cs);
149 if (!(backbuffer = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain,
150 buffer_idx, WINED3D_BACKBUFFER_TYPE_MONO)))
152 LeaveCriticalSection(&dxgi_cs);
153 return DXGI_ERROR_INVALID_CALL;
156 parent = wined3d_surface_get_parent(backbuffer);
157 hr = IUnknown_QueryInterface(parent, riid, surface);
158 LeaveCriticalSection(&dxgi_cs);
160 return hr;
163 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetFullscreenState(IDXGISwapChain *iface,
164 BOOL fullscreen, IDXGIOutput *target)
166 FIXME("iface %p, fullscreen %u, target %p stub!\n", iface, fullscreen, target);
168 return E_NOTIMPL;
171 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetFullscreenState(IDXGISwapChain *iface,
172 BOOL *fullscreen, IDXGIOutput **target)
174 FIXME("iface %p, fullscreen %p, target %p stub!\n", iface, fullscreen, target);
176 return E_NOTIMPL;
179 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetDesc(IDXGISwapChain *iface, DXGI_SWAP_CHAIN_DESC *desc)
181 struct dxgi_swapchain *swapchain = impl_from_IDXGISwapChain(iface);
182 struct wined3d_swapchain_desc wined3d_desc;
184 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
186 if (desc == NULL)
187 return E_INVALIDARG;
189 EnterCriticalSection(&dxgi_cs);
190 wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &wined3d_desc);
191 LeaveCriticalSection(&dxgi_cs);
193 FIXME("Ignoring ScanlineOrdering, Scaling, SwapEffect and Flags\n");
195 desc->BufferDesc.Width = wined3d_desc.backbuffer_width;
196 desc->BufferDesc.Height = wined3d_desc.backbuffer_height;
197 desc->BufferDesc.RefreshRate.Numerator = wined3d_desc.refresh_rate;
198 desc->BufferDesc.RefreshRate.Denominator = 1;
199 desc->BufferDesc.Format = dxgi_format_from_wined3dformat(wined3d_desc.backbuffer_format);
200 desc->BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
201 desc->BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
202 desc->SampleDesc.Count = wined3d_desc.multisample_type;
203 desc->SampleDesc.Quality = wined3d_desc.multisample_quality;
204 desc->BufferCount = wined3d_desc.backbuffer_count;
205 desc->OutputWindow = wined3d_desc.device_window;
206 desc->Windowed = wined3d_desc.windowed;
207 desc->SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
208 desc->Flags = 0;
210 return S_OK;
213 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_ResizeBuffers(IDXGISwapChain *iface,
214 UINT buffer_count, UINT width, UINT height, DXGI_FORMAT format, UINT flags)
216 FIXME("iface %p, buffer_count %u, width %u, height %u, format %s, flags %#x stub!\n",
217 iface, buffer_count, width, height, debug_dxgi_format(format), flags);
219 return E_NOTIMPL;
222 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_ResizeTarget(IDXGISwapChain *iface,
223 const DXGI_MODE_DESC *target_mode_desc)
225 FIXME("iface %p, target_mode_desc %p stub!\n", iface, target_mode_desc);
227 return E_NOTIMPL;
230 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetContainingOutput(IDXGISwapChain *iface, IDXGIOutput **output)
232 FIXME("iface %p, output %p stub!\n", iface, output);
234 return E_NOTIMPL;
237 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetFrameStatistics(IDXGISwapChain *iface, DXGI_FRAME_STATISTICS *stats)
239 FIXME("iface %p, stats %p stub!\n", iface, stats);
241 return E_NOTIMPL;
244 static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetLastPresentCount(IDXGISwapChain *iface, UINT *last_present_count)
246 FIXME("iface %p, last_present_count %p stub!\n", iface, last_present_count);
248 return E_NOTIMPL;
251 static const struct IDXGISwapChainVtbl dxgi_swapchain_vtbl =
253 /* IUnknown methods */
254 dxgi_swapchain_QueryInterface,
255 dxgi_swapchain_AddRef,
256 dxgi_swapchain_Release,
257 /* IDXGIObject methods */
258 dxgi_swapchain_SetPrivateData,
259 dxgi_swapchain_SetPrivateDataInterface,
260 dxgi_swapchain_GetPrivateData,
261 dxgi_swapchain_GetParent,
262 /* IDXGIDeviceSubObject methods */
263 dxgi_swapchain_GetDevice,
264 /* IDXGISwapChain methods */
265 dxgi_swapchain_Present,
266 dxgi_swapchain_GetBuffer,
267 dxgi_swapchain_SetFullscreenState,
268 dxgi_swapchain_GetFullscreenState,
269 dxgi_swapchain_GetDesc,
270 dxgi_swapchain_ResizeBuffers,
271 dxgi_swapchain_ResizeTarget,
272 dxgi_swapchain_GetContainingOutput,
273 dxgi_swapchain_GetFrameStatistics,
274 dxgi_swapchain_GetLastPresentCount,
277 static void STDMETHODCALLTYPE dxgi_swapchain_wined3d_object_released(void *parent)
279 HeapFree(GetProcessHeap(), 0, parent);
282 static const struct wined3d_parent_ops dxgi_swapchain_wined3d_parent_ops =
284 dxgi_swapchain_wined3d_object_released,
287 HRESULT dxgi_swapchain_init(struct dxgi_swapchain *swapchain, struct dxgi_device *device,
288 struct wined3d_swapchain_desc *desc)
290 HRESULT hr;
292 swapchain->IDXGISwapChain_iface.lpVtbl = &dxgi_swapchain_vtbl;
293 swapchain->refcount = 1;
295 if (FAILED(hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
296 &dxgi_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain)))
298 WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
299 return hr;
302 return S_OK;