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]);
75 EnterCriticalSection(&dxgi_cs);
76 IWineD3D_Release(This->wined3d);
77 LeaveCriticalSection(&dxgi_cs);
78 HeapFree(GetProcessHeap(), 0, This);
84 /* IDXGIObject methods */
86 static HRESULT STDMETHODCALLTYPE dxgi_factory_SetPrivateData(IWineDXGIFactory *iface,
87 REFGUID guid, UINT data_size, const void *data)
89 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
94 static HRESULT STDMETHODCALLTYPE dxgi_factory_SetPrivateDataInterface(IWineDXGIFactory *iface,
95 REFGUID guid, const IUnknown *object)
97 FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
102 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetPrivateData(IWineDXGIFactory *iface,
103 REFGUID guid, UINT *data_size, void *data)
105 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
110 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetParent(IWineDXGIFactory *iface, REFIID riid, void **parent)
112 FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
117 /* IDXGIFactory methods */
119 static HRESULT STDMETHODCALLTYPE dxgi_factory_EnumAdapters(IWineDXGIFactory *iface,
120 UINT adapter_idx, IDXGIAdapter **adapter)
122 struct dxgi_factory *This = (struct dxgi_factory *)iface;
124 TRACE("iface %p, adapter_idx %u, adapter %p\n", iface, adapter_idx, adapter);
126 if (!adapter) return DXGI_ERROR_INVALID_CALL;
128 if (adapter_idx >= This->adapter_count)
131 return DXGI_ERROR_NOT_FOUND;
134 *adapter = This->adapters[adapter_idx];
135 IDXGIAdapter_AddRef(*adapter);
137 TRACE("Returning adapter %p\n", *adapter);
142 static HRESULT STDMETHODCALLTYPE dxgi_factory_MakeWindowAssociation(IWineDXGIFactory *iface, HWND window, UINT flags)
144 FIXME("iface %p, window %p, flags %#x stub!\n\n", iface, window, flags);
149 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetWindowAssociation(IWineDXGIFactory *iface, HWND *window)
151 FIXME("iface %p, window %p stub!\n", iface, window);
156 static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IWineDXGIFactory *iface,
157 IUnknown *device, DXGI_SWAP_CHAIN_DESC *desc, IDXGISwapChain **swapchain)
159 struct dxgi_swapchain *object;
161 FIXME("iface %p, device %p, desc %p, swapchain %p partial stub!\n", iface, device, desc, swapchain);
163 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
166 ERR("Failed to allocate DXGI swapchain object memory\n");
167 return E_OUTOFMEMORY;
170 object->vtbl = &dxgi_swapchain_vtbl;
171 object->refcount = 1;
172 *swapchain = (IDXGISwapChain *)object;
174 TRACE("Created IDXGISwapChain %p\n", object);
179 static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSoftwareAdapter(IWineDXGIFactory *iface,
180 HMODULE swrast, IDXGIAdapter **adapter)
182 FIXME("iface %p, swrast %p, adapter %p stub!\n", iface, swrast, adapter);
187 /* IWineDXGIFactory methods */
189 static IWineD3D * STDMETHODCALLTYPE dxgi_factory_get_wined3d(IWineDXGIFactory *iface)
191 struct dxgi_factory *This = (struct dxgi_factory *)iface;
193 TRACE("iface %p\n", iface);
195 EnterCriticalSection(&dxgi_cs);
196 IWineD3D_AddRef(This->wined3d);
197 LeaveCriticalSection(&dxgi_cs);
198 return This->wined3d;
201 const struct IWineDXGIFactoryVtbl dxgi_factory_vtbl =
203 /* IUnknown methods */
204 dxgi_factory_QueryInterface,
206 dxgi_factory_Release,
207 /* IDXGIObject methods */
208 dxgi_factory_SetPrivateData,
209 dxgi_factory_SetPrivateDataInterface,
210 dxgi_factory_GetPrivateData,
211 dxgi_factory_GetParent,
212 /* IDXGIFactory methods */
213 dxgi_factory_EnumAdapters,
214 dxgi_factory_MakeWindowAssociation,
215 dxgi_factory_GetWindowAssociation,
216 dxgi_factory_CreateSwapChain,
217 dxgi_factory_CreateSoftwareAdapter,
218 /* IWineDXGIFactory methods */
219 dxgi_factory_get_wined3d,