winex11.drv: Map coordinates before calling send_mouse_input.
[wine/zf.git] / dlls / d3d10_1 / d3d10_1_main.c
blobf4fb1126ef2badc1d7509f9f6e513fe53556a838
1 /*
2 * Copyright 2014 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 "wine/debug.h"
22 #define COBJMACROS
23 #include "d3d10_1.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10);
27 HRESULT WINAPI D3D10CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter,
28 unsigned int flags, D3D_FEATURE_LEVEL feature_level, ID3D10Device **device);
30 #define WINE_D3D10_TO_STR(x) case x: return #x
32 static const char *debug_d3d10_driver_type(D3D10_DRIVER_TYPE driver_type)
34 switch (driver_type)
36 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_HARDWARE);
37 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_REFERENCE);
38 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_NULL);
39 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_SOFTWARE);
40 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_WARP);
41 default:
42 FIXME("Unrecognized D3D10_DRIVER_TYPE %#x.\n", driver_type);
43 return "unrecognized";
47 static const char *debug_d3d10_feature_level(D3D10_FEATURE_LEVEL1 feature_level)
49 switch (feature_level)
51 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_10_0);
52 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_10_1);
53 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_1);
54 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_2);
55 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_3);
56 default:
57 FIXME("Unrecognized D3D10_FEATURE_LEVEL1 %#x.\n", feature_level);
58 return "unrecognized";
62 #undef WINE_D3D10_TO_STR
64 static D3D_FEATURE_LEVEL d3d_feature_level_from_d3d10_1(D3D10_FEATURE_LEVEL1 level)
66 return (D3D_FEATURE_LEVEL)level;
69 static HRESULT d3d10_create_device1(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast,
70 UINT flags, D3D10_FEATURE_LEVEL1 hw_level, UINT sdk_version, ID3D10Device1 **device)
72 IDXGIFactory *factory;
73 HRESULT hr;
75 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, hw_level %s, sdk_version %d, device %p.\n",
76 adapter, debug_d3d10_driver_type(driver_type), swrast, flags,
77 debug_d3d10_feature_level(hw_level), sdk_version, device);
79 if (!device)
80 return E_INVALIDARG;
82 *device = NULL;
84 if (!hw_level)
85 return E_INVALIDARG;
87 if (adapter)
89 IDXGIAdapter_AddRef(adapter);
90 if (FAILED(hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory)))
92 WARN("Failed to get dxgi factory, hr %#x.\n", hr);
93 return hr;
96 else
98 if (FAILED(hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory)))
100 WARN("Failed to create dxgi factory, hr %#x.\n", hr);
101 return hr;
104 switch (driver_type)
106 case D3D10_DRIVER_TYPE_WARP:
107 FIXME("WARP driver not implemented, falling back to hardware.\n");
108 case D3D10_DRIVER_TYPE_HARDWARE:
110 if (FAILED(hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter)))
112 WARN("No adapters found, hr %#x.\n", hr);
113 IDXGIFactory_Release(factory);
114 return hr;
116 break;
119 case D3D10_DRIVER_TYPE_NULL:
120 FIXME("NULL device not implemented, falling back to refrast.\n");
121 /* Fall through, for now. */
122 case D3D10_DRIVER_TYPE_REFERENCE:
124 HMODULE refrast;
126 if (!(refrast = LoadLibraryA("d3d10ref.dll")))
128 WARN("Failed to load refrast, returning E_FAIL.\n");
129 IDXGIFactory_Release(factory);
130 return E_FAIL;
132 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
133 FreeLibrary(refrast);
134 if (FAILED(hr))
136 WARN("Failed to create a software adapter, hr %#x.\n", hr);
137 IDXGIFactory_Release(factory);
138 return hr;
140 break;
143 case D3D10_DRIVER_TYPE_SOFTWARE:
145 if (!swrast)
147 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
148 IDXGIFactory_Release(factory);
149 return E_FAIL;
151 if (FAILED(hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter)))
153 WARN("Failed to create a software adapter, hr %#x.\n", hr);
154 IDXGIFactory_Release(factory);
155 return hr;
157 break;
160 default:
161 FIXME("Unhandled driver type %#x.\n", driver_type);
162 IDXGIFactory_Release(factory);
163 return E_FAIL;
167 hr = D3D10CoreCreateDevice(factory, adapter, flags,
168 d3d_feature_level_from_d3d10_1(hw_level), (ID3D10Device **)device);
169 IDXGIAdapter_Release(adapter);
170 IDXGIFactory_Release(factory);
171 if (FAILED(hr))
173 WARN("Failed to create a device, hr %#x.\n", hr);
174 return hr;
177 TRACE("Created device %p.\n", *device);
179 return hr;
182 HRESULT WINAPI D3D10CreateDevice1(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast,
183 UINT flags, D3D10_FEATURE_LEVEL1 hw_level, UINT sdk_version, ID3D10Device1 **device)
185 return d3d10_create_device1(adapter, driver_type, swrast, flags, hw_level, sdk_version, device);
188 HRESULT WINAPI D3D10CreateDeviceAndSwapChain1(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
189 HMODULE swrast, UINT flags, D3D10_FEATURE_LEVEL1 feature_level, UINT sdk_version,
190 DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain, ID3D10Device1 **device)
192 IDXGIDevice *dxgi_device;
193 IDXGIFactory *factory;
194 HRESULT hr;
196 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, "
197 "feature_level %s, sdk_version %d, swapchain_desc %p, swapchain %p, device %p.\n",
198 adapter, debug_d3d10_driver_type(driver_type), swrast, flags,
199 debug_d3d10_feature_level(feature_level), sdk_version, swapchain_desc, swapchain, device);
201 if (swapchain)
202 *swapchain = NULL;
204 if (!device)
205 return E_INVALIDARG;
207 /* Avoid forwarding to D3D10CreateDevice1(), since it breaks applications
208 * hooking these entry-points. */
209 if (FAILED(hr = d3d10_create_device1(adapter, driver_type, swrast, flags, feature_level, sdk_version, device)))
211 WARN("Failed to create a device, returning %#x.\n", hr);
212 *device = NULL;
213 return hr;
216 if (swapchain)
218 if (FAILED(hr = ID3D10Device1_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device)))
220 ERR("Failed to get a dxgi device from the d3d10 device, returning %#x.\n", hr);
221 goto cleanup;
224 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
225 IDXGIDevice_Release(dxgi_device);
226 if (FAILED(hr))
228 ERR("Failed to get the device adapter, returning %#x.\n", hr);
229 goto cleanup;
232 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
233 IDXGIAdapter_Release(adapter);
234 if (FAILED(hr))
236 ERR("Failed to get the adapter factory, returning %#x.\n", hr);
237 goto cleanup;
240 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain);
241 IDXGIFactory_Release(factory);
242 if (FAILED(hr))
244 WARN("Failed to create a swapchain, returning %#x.\n", hr);
245 goto cleanup;
248 TRACE("Created IDXGISwapChain %p.\n", *swapchain);
251 return S_OK;
253 cleanup:
254 ID3D10Device1_Release(*device);
255 *device = NULL;
256 return hr;