bcrypt: Require macOS version 10.7 or newer for encryption support.
[wine.git] / dlls / d3d11 / d3d11_main.c
blob154a376b7848ff87061b8735266f580f8f916875
1 /*
2 * Direct3D 11
4 * Copyright 2008 Henri Verbeet for CodeWeavers
5 * Copyright 2013 Austin English
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wine/port.h"
26 #define D3D11_INIT_GUID
27 #include "d3d11_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
31 static const char *debug_d3d_driver_type(D3D_DRIVER_TYPE driver_type)
33 switch (driver_type)
35 #define D3D11_TO_STR(x) case x: return #x
36 D3D11_TO_STR(D3D_DRIVER_TYPE_UNKNOWN);
37 D3D11_TO_STR(D3D_DRIVER_TYPE_HARDWARE);
38 D3D11_TO_STR(D3D_DRIVER_TYPE_REFERENCE);
39 D3D11_TO_STR(D3D_DRIVER_TYPE_NULL);
40 D3D11_TO_STR(D3D_DRIVER_TYPE_SOFTWARE);
41 D3D11_TO_STR(D3D_DRIVER_TYPE_WARP);
42 #undef D3D11_TO_STR
43 default:
44 return wine_dbg_sprintf("Unrecognized D3D_DRIVER_TYPE %#x\n", driver_type);
48 static HRESULT WINAPI layer_init(enum dxgi_device_layer_id id, DWORD *count, DWORD *values)
50 TRACE("id %#x, count %p, values %p\n", id, count, values);
52 if (id != DXGI_DEVICE_LAYER_D3D10_DEVICE)
54 WARN("Unknown layer id %#x\n", id);
55 return E_NOTIMPL;
58 return S_OK;
61 static UINT WINAPI layer_get_size(enum dxgi_device_layer_id id, struct layer_get_size_args *args, DWORD unknown0)
63 TRACE("id %#x, args %p, unknown0 %#x\n", id, args, unknown0);
65 if (id != DXGI_DEVICE_LAYER_D3D10_DEVICE)
67 WARN("Unknown layer id %#x\n", id);
68 return 0;
71 return sizeof(struct d3d_device);
74 static HRESULT WINAPI layer_create(enum dxgi_device_layer_id id, void **layer_base, DWORD unknown0,
75 void *device_object, REFIID riid, void **device_layer)
77 struct d3d_device *object;
79 TRACE("id %#x, layer_base %p, unknown0 %#x, device_object %p, riid %s, device_layer %p\n",
80 id, layer_base, unknown0, device_object, debugstr_guid(riid), device_layer);
82 if (id != DXGI_DEVICE_LAYER_D3D10_DEVICE)
84 WARN("Unknown layer id %#x\n", id);
85 *device_layer = NULL;
86 return E_NOTIMPL;
89 object = *layer_base;
90 d3d_device_init(object, device_object);
91 *device_layer = &object->IUnknown_inner;
93 TRACE("Created d3d10 device at %p\n", object);
95 return S_OK;
98 static void WINAPI layer_set_feature_level(enum dxgi_device_layer_id id, void *device,
99 D3D_FEATURE_LEVEL feature_level)
101 struct d3d_device *d3d_device = device;
103 TRACE("id %#x, device %p, feature_level %#x.\n", id, device, feature_level);
105 if (id != DXGI_DEVICE_LAYER_D3D10_DEVICE)
107 WARN("Unknown layer id %#x.\n", id);
108 return;
111 d3d_device->feature_level = feature_level;
114 HRESULT WINAPI D3D11CoreRegisterLayers(void)
116 static const struct dxgi_device_layer layers[] =
118 {DXGI_DEVICE_LAYER_D3D10_DEVICE, layer_init, layer_get_size, layer_create, layer_set_feature_level},
121 DXGID3D10RegisterLayers(layers, ARRAY_SIZE(layers));
123 return S_OK;
126 HRESULT WINAPI D3D11CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter, UINT flags,
127 const D3D_FEATURE_LEVEL *feature_levels, UINT levels, ID3D11Device **device)
129 IUnknown *dxgi_device;
130 HMODULE d3d11;
131 HRESULT hr;
133 TRACE("factory %p, adapter %p, flags %#x, feature_levels %p, levels %u, device %p.\n",
134 factory, adapter, flags, feature_levels, levels, device);
136 d3d11 = GetModuleHandleA("d3d11.dll");
137 hr = DXGID3D10CreateDevice(d3d11, factory, adapter, flags, feature_levels, levels, (void **)&dxgi_device);
138 if (FAILED(hr))
140 WARN("Failed to create device, returning %#x.\n", hr);
141 return hr;
144 hr = IUnknown_QueryInterface(dxgi_device, &IID_ID3D11Device, (void **)device);
145 IUnknown_Release(dxgi_device);
146 if (FAILED(hr))
148 ERR("Failed to query ID3D11Device interface, returning E_FAIL.\n");
149 return E_FAIL;
152 return S_OK;
155 HRESULT WINAPI D3D11CreateDevice(IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags,
156 const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, ID3D11Device **device_out,
157 D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context)
159 static const D3D_FEATURE_LEVEL default_feature_levels[] =
161 D3D_FEATURE_LEVEL_11_0,
162 D3D_FEATURE_LEVEL_10_1,
163 D3D_FEATURE_LEVEL_10_0,
164 D3D_FEATURE_LEVEL_9_3,
165 D3D_FEATURE_LEVEL_9_2,
166 D3D_FEATURE_LEVEL_9_1,
168 IDXGIFactory *factory;
169 ID3D11Device *device;
170 HRESULT hr;
172 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, feature_levels %p, levels %u, sdk_version %u, "
173 "device %p, obtained_feature_level %p, immediate_context %p.\n",
174 adapter, debug_d3d_driver_type(driver_type), swrast, flags, feature_levels, levels, sdk_version,
175 device_out, obtained_feature_level, immediate_context);
177 if (device_out)
178 *device_out = NULL;
179 if (obtained_feature_level)
180 *obtained_feature_level = 0;
181 if (immediate_context)
182 *immediate_context = NULL;
184 if (adapter)
186 IDXGIAdapter_AddRef(adapter);
187 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
188 if (FAILED(hr))
190 WARN("Failed to get dxgi factory, returning %#x.\n", hr);
191 return hr;
194 else
196 hr = CreateDXGIFactory1(&IID_IDXGIFactory, (void **)&factory);
197 if (FAILED(hr))
199 WARN("Failed to create dxgi factory, returning %#x.\n", hr);
200 return hr;
203 switch(driver_type)
205 case D3D_DRIVER_TYPE_HARDWARE:
207 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
208 if (FAILED(hr))
210 WARN("No adapters found, returning %#x.\n", hr);
211 IDXGIFactory_Release(factory);
212 return hr;
214 break;
217 case D3D_DRIVER_TYPE_NULL:
218 FIXME("NULL device not implemented, falling back to refrast.\n");
219 /* fall through, for now */
220 case D3D_DRIVER_TYPE_REFERENCE:
222 HMODULE refrast = LoadLibraryA("d3d11ref.dll");
223 if (!refrast)
225 WARN("Failed to load refrast, returning E_FAIL.\n");
226 IDXGIFactory_Release(factory);
227 return E_FAIL;
229 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
230 FreeLibrary(refrast);
231 if (FAILED(hr))
233 WARN("Failed to create a software adapter, returning %#x.\n", hr);
234 IDXGIFactory_Release(factory);
235 return hr;
237 break;
240 case D3D_DRIVER_TYPE_SOFTWARE:
242 if (!swrast)
244 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
245 IDXGIFactory_Release(factory);
246 return E_FAIL;
248 hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
249 if (FAILED(hr))
251 WARN("Failed to create a software adapter, returning %#x.\n", hr);
252 IDXGIFactory_Release(factory);
253 return hr;
255 break;
258 default:
259 FIXME("Unhandled driver type %#x.\n", driver_type);
260 IDXGIFactory_Release(factory);
261 return E_FAIL;
265 if (!feature_levels)
267 feature_levels = default_feature_levels;
268 levels = ARRAY_SIZE(default_feature_levels);
270 hr = D3D11CoreCreateDevice(factory, adapter, flags, feature_levels, levels, &device);
271 IDXGIAdapter_Release(adapter);
272 IDXGIFactory_Release(factory);
273 if (FAILED(hr))
275 WARN("Failed to create a device, returning %#x.\n", hr);
276 return hr;
279 TRACE("Created ID3D11Device %p.\n", device);
281 if (obtained_feature_level)
282 *obtained_feature_level = ID3D11Device_GetFeatureLevel(device);
284 if (immediate_context)
285 ID3D11Device_GetImmediateContext(device, immediate_context);
287 if (device_out)
288 *device_out = device;
289 else
290 ID3D11Device_Release(device);
292 return (device_out || immediate_context) ? S_OK : S_FALSE;
295 HRESULT WINAPI D3D11CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type,
296 HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels,
297 UINT sdk_version, const DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain,
298 ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context)
300 DXGI_SWAP_CHAIN_DESC desc;
301 IDXGIDevice *dxgi_device;
302 IDXGIFactory *factory;
303 ID3D11Device *device;
304 HRESULT hr;
306 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, feature_levels %p, levels %u, sdk_version %u, "
307 "swapchain_desc %p, swapchain %p, device %p, obtained_feature_level %p, immediate_context %p.\n",
308 adapter, debug_d3d_driver_type(driver_type), swrast, flags, feature_levels, levels, sdk_version,
309 swapchain_desc, swapchain, device_out, obtained_feature_level, immediate_context);
311 if (swapchain)
312 *swapchain = NULL;
313 if (device_out)
314 *device_out = NULL;
316 if (FAILED(hr = D3D11CreateDevice(adapter, driver_type, swrast, flags, feature_levels, levels, sdk_version,
317 &device, obtained_feature_level, immediate_context)))
319 WARN("Failed to create a device, returning %#x.\n", hr);
320 return hr;
323 if (swapchain)
325 if (FAILED(hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device)))
327 ERR("Failed to get a dxgi device from the d3d11 device, returning %#x.\n", hr);
328 goto cleanup;
331 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
332 IDXGIDevice_Release(dxgi_device);
333 if (FAILED(hr))
335 ERR("Failed to get the device adapter, returning %#x.\n", hr);
336 goto cleanup;
339 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
340 IDXGIAdapter_Release(adapter);
341 if (FAILED(hr))
343 ERR("Failed to get the adapter factory, returning %#x.\n", hr);
344 goto cleanup;
347 desc = *swapchain_desc;
348 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, swapchain);
349 IDXGIFactory_Release(factory);
350 if (FAILED(hr))
352 WARN("Failed to create a swapchain, returning %#x.\n", hr);
353 goto cleanup;
356 TRACE("Created IDXGISwapChain %p.\n", *swapchain);
359 if (device_out)
360 *device_out = device;
361 else
362 ID3D11Device_Release(device);
364 return (swapchain || device_out || immediate_context) ? S_OK : S_FALSE;
366 cleanup:
367 ID3D11Device_Release(device);
368 if (obtained_feature_level)
369 *obtained_feature_level = 0;
370 if (immediate_context)
372 ID3D11DeviceContext_Release(*immediate_context);
373 *immediate_context = NULL;
376 return hr;