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 /* IUnknown methods */
29 static HRESULT STDMETHODCALLTYPE dxgi_factory_QueryInterface(IWineDXGIFactory *iface, REFIID riid, void **object)
31 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDXGIObject)
35 || IsEqualGUID(riid, &IID_IDXGIFactory)
36 || IsEqualGUID(riid, &IID_IWineDXGIFactory))
38 IUnknown_AddRef(iface);
43 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
49 static ULONG STDMETHODCALLTYPE dxgi_factory_AddRef(IWineDXGIFactory *iface)
51 struct dxgi_factory *This = (struct dxgi_factory *)iface;
52 ULONG refcount = InterlockedIncrement(&This->refcount);
54 TRACE("%p increasing refcount to %u\n", This, refcount);
59 static ULONG STDMETHODCALLTYPE dxgi_factory_Release(IWineDXGIFactory *iface)
61 struct dxgi_factory *This = (struct dxgi_factory *)iface;
62 ULONG refcount = InterlockedDecrement(&This->refcount);
64 TRACE("%p decreasing refcount to %u\n", This, refcount);
70 for (i = 0; i < This->adapter_count; ++i)
72 IDXGIAdapter_Release(This->adapters[i]);
74 HeapFree(GetProcessHeap(), 0, This->adapters);
76 EnterCriticalSection(&dxgi_cs);
77 IWineD3D_Release(This->wined3d);
78 LeaveCriticalSection(&dxgi_cs);
79 HeapFree(GetProcessHeap(), 0, This);
85 /* IDXGIObject methods */
87 static HRESULT STDMETHODCALLTYPE dxgi_factory_SetPrivateData(IWineDXGIFactory *iface,
88 REFGUID guid, UINT data_size, const void *data)
90 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
95 static HRESULT STDMETHODCALLTYPE dxgi_factory_SetPrivateDataInterface(IWineDXGIFactory *iface,
96 REFGUID guid, const IUnknown *object)
98 FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
103 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetPrivateData(IWineDXGIFactory *iface,
104 REFGUID guid, UINT *data_size, void *data)
106 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
111 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetParent(IWineDXGIFactory *iface, REFIID riid, void **parent)
113 FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
118 /* IDXGIFactory methods */
120 static HRESULT STDMETHODCALLTYPE dxgi_factory_EnumAdapters(IWineDXGIFactory *iface,
121 UINT adapter_idx, IDXGIAdapter **adapter)
123 struct dxgi_factory *This = (struct dxgi_factory *)iface;
125 TRACE("iface %p, adapter_idx %u, adapter %p\n", iface, adapter_idx, adapter);
127 if (!adapter) return DXGI_ERROR_INVALID_CALL;
129 if (adapter_idx >= This->adapter_count)
132 return DXGI_ERROR_NOT_FOUND;
135 *adapter = This->adapters[adapter_idx];
136 IDXGIAdapter_AddRef(*adapter);
138 TRACE("Returning adapter %p\n", *adapter);
143 static HRESULT STDMETHODCALLTYPE dxgi_factory_MakeWindowAssociation(IWineDXGIFactory *iface, HWND window, UINT flags)
145 FIXME("iface %p, window %p, flags %#x stub!\n\n", iface, window, flags);
150 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetWindowAssociation(IWineDXGIFactory *iface, HWND *window)
152 FIXME("iface %p, window %p stub!\n", iface, window);
157 /* TODO: The DXGI swapchain desc is a bit nicer than WINED3DPRESENT_PARAMETERS,
158 * change wined3d to use a structure more similar to DXGI. */
159 static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IWineDXGIFactory *iface,
160 IUnknown *device, DXGI_SWAP_CHAIN_DESC *desc, IDXGISwapChain **swapchain)
162 WINED3DPRESENT_PARAMETERS present_parameters;
163 IWineD3DSwapChain *wined3d_swapchain;
164 IWineD3DDevice *wined3d_device;
165 IWineDXGIDevice *dxgi_device;
169 FIXME("iface %p, device %p, desc %p, swapchain %p partial stub!\n", iface, device, desc, swapchain);
171 hr = IUnknown_QueryInterface(device, &IID_IWineDXGIDevice, (void **)&dxgi_device);
174 ERR("This is not the device we're looking for\n");
178 wined3d_device = IWineDXGIDevice_get_wined3d_device(dxgi_device);
179 IWineDXGIDevice_Release(dxgi_device);
181 count = IWineD3DDevice_GetNumberOfSwapChains(wined3d_device);
184 FIXME("Only a single swapchain supported.\n");
185 IWineD3DDevice_Release(wined3d_device);
189 if (!desc->OutputWindow)
191 FIXME("No output window, should use factory output window\n");
194 FIXME("Ignoring SwapEffect and Flags\n");
196 present_parameters.BackBufferWidth = desc->BufferDesc.Width;
197 present_parameters.BackBufferHeight = desc->BufferDesc.Height;
198 present_parameters.BackBufferFormat = wined3dformat_from_dxgi_format(desc->BufferDesc.Format);
199 present_parameters.BackBufferCount = desc->BufferCount;
200 if (desc->SampleDesc.Count > 1)
202 present_parameters.MultiSampleType = desc->SampleDesc.Count;
203 present_parameters.MultiSampleQuality = desc->SampleDesc.Quality;
207 present_parameters.MultiSampleType = WINED3DMULTISAMPLE_NONE;
208 present_parameters.MultiSampleQuality = 0;
210 present_parameters.SwapEffect = WINED3DSWAPEFFECT_DISCARD;
211 present_parameters.hDeviceWindow = desc->OutputWindow;
212 present_parameters.Windowed = desc->Windowed;
213 present_parameters.EnableAutoDepthStencil = FALSE;
214 present_parameters.AutoDepthStencilFormat = 0;
215 present_parameters.Flags = 0; /* WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL? */
216 present_parameters.FullScreen_RefreshRateInHz =
217 desc->BufferDesc.RefreshRate.Numerator / desc->BufferDesc.RefreshRate.Denominator;
218 present_parameters.PresentationInterval = WINED3DPRESENT_INTERVAL_DEFAULT;
220 hr = IWineD3DDevice_Init3D(wined3d_device, &present_parameters);
223 WARN("Failed to initialize 3D, returning %#x\n", hr);
224 IWineD3DDevice_Release(wined3d_device);
228 hr = IWineD3DDevice_GetSwapChain(wined3d_device, 0, &wined3d_swapchain);
229 IWineD3DDevice_Release(wined3d_device);
232 WARN("Failed to get swapchain, returning %#x\n", hr);
236 hr = IWineD3DSwapChain_GetParent(wined3d_swapchain, (IUnknown **)swapchain);
237 IUnknown_Release(wined3d_swapchain);
240 WARN("Failed to get swapchain, returning %#x\n", hr);
244 /* FIXME? The swapchain is created with refcount 1 by the wined3d device,
245 * but the wined3d device can't hold a real reference. */
246 IUnknown_Release(*swapchain);
248 TRACE("Created IDXGISwapChain %p\n", *swapchain);
253 static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSoftwareAdapter(IWineDXGIFactory *iface,
254 HMODULE swrast, IDXGIAdapter **adapter)
256 FIXME("iface %p, swrast %p, adapter %p stub!\n", iface, swrast, adapter);
261 /* IWineDXGIFactory methods */
263 static IWineD3D * STDMETHODCALLTYPE dxgi_factory_get_wined3d(IWineDXGIFactory *iface)
265 struct dxgi_factory *This = (struct dxgi_factory *)iface;
267 TRACE("iface %p\n", iface);
269 EnterCriticalSection(&dxgi_cs);
270 IWineD3D_AddRef(This->wined3d);
271 LeaveCriticalSection(&dxgi_cs);
272 return This->wined3d;
275 const struct IWineDXGIFactoryVtbl dxgi_factory_vtbl =
277 /* IUnknown methods */
278 dxgi_factory_QueryInterface,
280 dxgi_factory_Release,
281 /* IDXGIObject methods */
282 dxgi_factory_SetPrivateData,
283 dxgi_factory_SetPrivateDataInterface,
284 dxgi_factory_GetPrivateData,
285 dxgi_factory_GetParent,
286 /* IDXGIFactory methods */
287 dxgi_factory_EnumAdapters,
288 dxgi_factory_MakeWindowAssociation,
289 dxgi_factory_GetWindowAssociation,
290 dxgi_factory_CreateSwapChain,
291 dxgi_factory_CreateSoftwareAdapter,
292 /* IWineDXGIFactory methods */
293 dxgi_factory_get_wined3d,