browseui: Make a function static.
[wine] / dlls / dxgi / factory.c
1 /*
2  * Copyright 2008 Henri Verbeet for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  *
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include "dxgi_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
26
27 /* IUnknown methods */
28
29 static HRESULT STDMETHODCALLTYPE dxgi_factory_QueryInterface(IWineDXGIFactory *iface, REFIID riid, void **object)
30 {
31     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
32
33     if (IsEqualGUID(riid, &IID_IUnknown)
34             || IsEqualGUID(riid, &IID_IDXGIObject)
35             || IsEqualGUID(riid, &IID_IDXGIFactory)
36             || IsEqualGUID(riid, &IID_IWineDXGIFactory))
37     {
38         IUnknown_AddRef(iface);
39         *object = iface;
40         return S_OK;
41     }
42
43     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
44
45     *object = NULL;
46     return E_NOINTERFACE;
47 }
48
49 static ULONG STDMETHODCALLTYPE dxgi_factory_AddRef(IWineDXGIFactory *iface)
50 {
51     struct dxgi_factory *This = (struct dxgi_factory *)iface;
52     ULONG refcount = InterlockedIncrement(&This->refcount);
53
54     TRACE("%p increasing refcount to %u\n", This, refcount);
55
56     return refcount;
57 }
58
59 static ULONG STDMETHODCALLTYPE dxgi_factory_Release(IWineDXGIFactory *iface)
60 {
61     struct dxgi_factory *This = (struct dxgi_factory *)iface;
62     ULONG refcount = InterlockedDecrement(&This->refcount);
63
64     TRACE("%p decreasing refcount to %u\n", This, refcount);
65
66     if (!refcount)
67     {
68         UINT i;
69
70         for (i = 0; i < This->adapter_count; ++i)
71         {
72             IDXGIAdapter_Release(This->adapters[i]);
73         }
74
75         EnterCriticalSection(&dxgi_cs);
76         IWineD3D_Release(This->wined3d);
77         LeaveCriticalSection(&dxgi_cs);
78         HeapFree(GetProcessHeap(), 0, This);
79     }
80
81     return refcount;
82 }
83
84 /* IDXGIObject methods */
85
86 static HRESULT STDMETHODCALLTYPE dxgi_factory_SetPrivateData(IWineDXGIFactory *iface,
87         REFGUID guid, UINT data_size, const void *data)
88 {
89     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
90
91     return E_NOTIMPL;
92 }
93
94 static HRESULT STDMETHODCALLTYPE dxgi_factory_SetPrivateDataInterface(IWineDXGIFactory *iface,
95         REFGUID guid, const IUnknown *object)
96 {
97     FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
98
99     return E_NOTIMPL;
100 }
101
102 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetPrivateData(IWineDXGIFactory *iface,
103         REFGUID guid, UINT *data_size, void *data)
104 {
105     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
106
107     return E_NOTIMPL;
108 }
109
110 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetParent(IWineDXGIFactory *iface, REFIID riid, void **parent)
111 {
112     FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
113
114     return E_NOTIMPL;
115 }
116
117 /* IDXGIFactory methods */
118
119 static HRESULT STDMETHODCALLTYPE dxgi_factory_EnumAdapters(IWineDXGIFactory *iface,
120         UINT adapter_idx, IDXGIAdapter **adapter)
121 {
122     struct dxgi_factory *This = (struct dxgi_factory *)iface;
123
124     TRACE("iface %p, adapter_idx %u, adapter %p\n", iface, adapter_idx, adapter);
125
126     if (!adapter) return DXGI_ERROR_INVALID_CALL;
127
128     if (adapter_idx >= This->adapter_count)
129     {
130         *adapter = NULL;
131         return DXGI_ERROR_NOT_FOUND;
132     }
133
134     *adapter = (IDXGIAdapter *)This->adapters[adapter_idx];
135     IDXGIAdapter_AddRef(*adapter);
136
137     TRACE("Returning adapter %p\n", *adapter);
138
139     return S_OK;
140 }
141
142 static HRESULT STDMETHODCALLTYPE dxgi_factory_MakeWindowAssociation(IWineDXGIFactory *iface, HWND window, UINT flags)
143 {
144     FIXME("iface %p, window %p, flags %#x stub!\n\n", iface, window, flags);
145
146     return E_NOTIMPL;
147 }
148
149 static HRESULT STDMETHODCALLTYPE dxgi_factory_GetWindowAssociation(IWineDXGIFactory *iface, HWND *window)
150 {
151     FIXME("iface %p, window %p stub!\n", iface, window);
152
153     return E_NOTIMPL;
154 }
155
156 static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IWineDXGIFactory *iface,
157         IUnknown *device, DXGI_SWAP_CHAIN_DESC *desc, IDXGISwapChain **swapchain)
158 {
159     struct dxgi_swapchain *object;
160
161     FIXME("iface %p, device %p, desc %p, swapchain %p partial stub!\n", iface, device, desc, swapchain);
162
163     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
164     if (!object)
165     {
166         ERR("Failed to allocate DXGI swapchain object memory\n");
167         return E_OUTOFMEMORY;
168     }
169
170     object->vtbl = &dxgi_swapchain_vtbl;
171     object->refcount = 1;
172     *swapchain = (IDXGISwapChain *)object;
173
174     TRACE("Created IDXGISwapChain %p\n", object);
175
176     return S_OK;
177 }
178
179 static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSoftwareAdapter(IWineDXGIFactory *iface,
180         HMODULE swrast, IDXGIAdapter **adapter)
181 {
182     FIXME("iface %p, swrast %p, adapter %p stub!\n", iface, swrast, adapter);
183
184     return E_NOTIMPL;
185 }
186
187 /* IWineDXGIFactory methods */
188
189 static IWineD3D * STDMETHODCALLTYPE dxgi_factory_get_wined3d(IWineDXGIFactory *iface)
190 {
191     struct dxgi_factory *This = (struct dxgi_factory *)iface;
192
193     TRACE("iface %p\n", iface);
194
195     EnterCriticalSection(&dxgi_cs);
196     IWineD3D_AddRef(This->wined3d);
197     LeaveCriticalSection(&dxgi_cs);
198     return This->wined3d;
199 }
200
201 const struct IWineDXGIFactoryVtbl dxgi_factory_vtbl =
202 {
203     /* IUnknown methods */
204     dxgi_factory_QueryInterface,
205     dxgi_factory_AddRef,
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,
220 };