winex11: Remove the XRender support in the X11 driver StretchBlt implementation.
[wine] / dlls / d3d10 / d3d10_main.c
1 /*
2  * Direct3D 10
3  *
4  * Copyright 2007 Andras Kovacs
5  * Copyright 2009 Henri Verbeet for CodeWeavers
6  *
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.
11  *
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.
16  *
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
20  *
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include "d3d10_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d10);
29
30 /* At process attach */
31 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
32 {
33     TRACE("fdwReason=%d\n", fdwReason);
34     switch(fdwReason)
35     {
36     case DLL_PROCESS_ATTACH:
37         DisableThreadLibraryCalls( hInstDLL );
38         break;
39     }
40     return TRUE;
41 }
42
43 HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
44         HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
45 {
46     IDXGIFactory *factory;
47     HRESULT hr;
48
49     TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d, device %p\n",
50             adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, device);
51
52     if (adapter)
53     {
54         IDXGIAdapter_AddRef(adapter);
55         hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
56         if (FAILED(hr))
57         {
58             WARN("Failed to get dxgi factory, returning %#x\n", hr);
59             return hr;
60         }
61     }
62     else
63     {
64         hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory);
65         if (FAILED(hr))
66         {
67             WARN("Failed to create dxgi factory, returning %#x\n", hr);
68             return hr;
69         }
70
71         switch(driver_type)
72         {
73             case D3D10_DRIVER_TYPE_HARDWARE:
74             {
75                 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
76                 if (FAILED(hr))
77                 {
78                     WARN("No adapters found, returning %#x\n", hr);
79                     IDXGIFactory_Release(factory);
80                     return hr;
81                 }
82                 break;
83             }
84
85             case D3D10_DRIVER_TYPE_NULL:
86                 FIXME("NULL device not implemented, falling back to refrast\n");
87             case D3D10_DRIVER_TYPE_REFERENCE:
88             {
89                 HMODULE refrast = LoadLibraryA("d3d10ref.dll");
90                 if (!refrast)
91                 {
92                     WARN("Failed to load refrast, returning E_FAIL\n");
93                     IDXGIFactory_Release(factory);
94                     return E_FAIL;
95                 }
96                 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
97                 FreeLibrary(refrast);
98                 if (FAILED(hr))
99                 {
100                     WARN("Failed to create a software adapter, returning %#x\n", hr);
101                     IDXGIFactory_Release(factory);
102                     return hr;
103                 }
104                 break;
105             }
106
107             case D3D10_DRIVER_TYPE_SOFTWARE:
108             {
109                 if (!swrast)
110                 {
111                     WARN("Software device requested, but NULL swrast passed, returning E_FAIL\n");
112                     IDXGIFactory_Release(factory);
113                     return E_FAIL;
114                 }
115                 hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
116                 if (FAILED(hr))
117                 {
118                     WARN("Failed to create a software adapter, returning %#x\n", hr);
119                     IDXGIFactory_Release(factory);
120                     return hr;
121                 }
122                 break;
123             }
124         }
125     }
126
127     hr = D3D10CoreCreateDevice(factory, adapter, flags, NULL, device);
128     IDXGIAdapter_Release(adapter);
129     IDXGIFactory_Release(factory);
130     if (FAILED(hr))
131     {
132         WARN("Failed to create a device, returning %#x\n", hr);
133         return hr;
134     }
135
136     TRACE("Created ID3D10Device %p\n", *device);
137
138     return hr;
139 }
140
141 HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
142         HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc,
143         IDXGISwapChain **swapchain, ID3D10Device **device)
144 {
145     IDXGIDevice *dxgi_device;
146     IDXGIFactory *factory;
147     HRESULT hr;
148
149     TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d,\n"
150             "\tswapchain_desc %p, swapchain %p, device %p\n",
151             adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version,
152             swapchain_desc, swapchain, device);
153
154     hr = D3D10CreateDevice(adapter, driver_type, swrast, flags, sdk_version, device);
155     if (FAILED(hr))
156     {
157         WARN("Failed to create a device, returning %#x\n", hr);
158         *device = NULL;
159         return hr;
160     }
161
162     TRACE("Created ID3D10Device %p\n", *device);
163
164     hr = ID3D10Device_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device);
165     if (FAILED(hr))
166     {
167         ERR("Failed to get a dxgi device from the d3d10 device, returning %#x\n", hr);
168         ID3D10Device_Release(*device);
169         *device = NULL;
170         return hr;
171     }
172
173     hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
174     IDXGIDevice_Release(dxgi_device);
175     if (FAILED(hr))
176     {
177         ERR("Failed to get the device adapter, returning %#x\n", hr);
178         ID3D10Device_Release(*device);
179         *device = NULL;
180         return hr;
181     }
182
183     hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
184     IDXGIAdapter_Release(adapter);
185     if (FAILED(hr))
186     {
187         ERR("Failed to get the adapter factory, returning %#x\n", hr);
188         ID3D10Device_Release(*device);
189         *device = NULL;
190         return hr;
191     }
192
193     hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain);
194     IDXGIFactory_Release(factory);
195     if (FAILED(hr))
196     {
197         ID3D10Device_Release(*device);
198         *device = NULL;
199
200         WARN("Failed to create a swapchain, returning %#x\n", hr);
201         return hr;
202     }
203
204     TRACE("Created IDXGISwapChain %p\n", *swapchain);
205
206     return S_OK;
207 }
208
209 HRESULT WINAPI D3D10CreateEffectFromMemory(void *data, SIZE_T data_size, UINT flags,
210         ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3D10Effect **effect)
211 {
212     struct d3d10_effect *object;
213     HRESULT hr;
214
215     FIXME("data %p, data_size %lu, flags %#x, device %p, effect_pool %p, effect %p stub!\n",
216             data, data_size, flags, device, effect_pool, effect);
217
218     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
219     if (!object)
220     {
221         ERR("Failed to allocate D3D10 effect object memory\n");
222         return E_OUTOFMEMORY;
223     }
224
225     object->ID3D10Effect_iface.lpVtbl = &d3d10_effect_vtbl;
226     object->refcount = 1;
227     ID3D10Device_AddRef(device);
228     object->device = device;
229
230     hr = d3d10_effect_parse(object, data, data_size);
231     if (FAILED(hr))
232     {
233         ERR("Failed to parse effect\n");
234         IUnknown_Release(&object->ID3D10Effect_iface);
235         return hr;
236     }
237
238     *effect = &object->ID3D10Effect_iface;
239
240     TRACE("Created ID3D10Effect %p\n", object);
241
242     return S_OK;
243 }
244
245 LPCSTR WINAPI D3D10GetVertexShaderProfile(ID3D10Device *device)
246 {
247     FIXME("device %p stub!\n", device);
248
249     return "vs_4_0";
250 }
251
252 LPCSTR WINAPI D3D10GetGeometryShaderProfile(ID3D10Device *device)
253 {
254     FIXME("device %p stub!\n", device);
255
256     return "gs_4_0";
257 }
258
259 LPCSTR WINAPI D3D10GetPixelShaderProfile(ID3D10Device *device)
260 {
261     FIXME("device %p stub!\n", device);
262
263     return "ps_4_0";
264 }
265
266 HRESULT WINAPI D3D10ReflectShader(const void *data, SIZE_T data_size, ID3D10ShaderReflection **reflector)
267 {
268     struct d3d10_shader_reflection *object;
269
270     FIXME("data %p, data_size %lu, reflector %p stub!\n", data, data_size, reflector);
271
272     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
273     if (!object)
274     {
275         ERR("Failed to allocate D3D10 shader reflection object memory\n");
276         return E_OUTOFMEMORY;
277     }
278
279     object->ID3D10ShaderReflection_iface.lpVtbl = &d3d10_shader_reflection_vtbl;
280     object->refcount = 1;
281
282     *reflector = &object->ID3D10ShaderReflection_iface;
283
284     TRACE("Created ID3D10ShaderReflection %p\n", object);
285
286     return S_OK;
287 }