gdiplus: Fix the clipping region calculation.
[wine/multimedia.git] / dlls / d3d10 / d3d10_main.c
blob5c3eec87f1452d045bb9f95e9c80ddfd3674ff9b
1 /*
2 * Direct3D 10
4 * Copyright 2007 Andras Kovacs
5 * Copyright 2009 Henri Verbeet for CodeWeavers
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 #include "d3d10_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d10);
30 /* At process attach */
31 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
33 TRACE("fdwReason=%d\n", fdwReason);
34 switch(fdwReason)
36 case DLL_PROCESS_ATTACH:
37 DisableThreadLibraryCalls( hInstDLL );
38 break;
40 return TRUE;
43 HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
44 HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
46 IDXGIFactory *factory;
47 HRESULT hr;
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);
52 if (adapter)
54 IDXGIAdapter_AddRef(adapter);
55 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
56 if (FAILED(hr))
58 WARN("Failed to get dxgi factory, returning %#x\n", hr);
59 return hr;
62 else
64 hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory);
65 if (FAILED(hr))
67 WARN("Failed to create dxgi factory, returning %#x\n", hr);
68 return hr;
71 switch(driver_type)
73 case D3D10_DRIVER_TYPE_HARDWARE:
75 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
76 if (FAILED(hr))
78 WARN("No adapters found, returning %#x\n", hr);
79 IDXGIFactory_Release(factory);
80 return hr;
82 break;
85 case D3D10_DRIVER_TYPE_NULL:
86 FIXME("NULL device not implemented, falling back to refrast\n");
87 /* fall through, for now */
88 case D3D10_DRIVER_TYPE_REFERENCE:
90 HMODULE refrast = LoadLibraryA("d3d10ref.dll");
91 if (!refrast)
93 WARN("Failed to load refrast, returning E_FAIL\n");
94 IDXGIFactory_Release(factory);
95 return E_FAIL;
97 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
98 FreeLibrary(refrast);
99 if (FAILED(hr))
101 WARN("Failed to create a software adapter, returning %#x\n", hr);
102 IDXGIFactory_Release(factory);
103 return hr;
105 break;
108 case D3D10_DRIVER_TYPE_SOFTWARE:
110 if (!swrast)
112 WARN("Software device requested, but NULL swrast passed, returning E_FAIL\n");
113 IDXGIFactory_Release(factory);
114 return E_FAIL;
116 hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
117 if (FAILED(hr))
119 WARN("Failed to create a software adapter, returning %#x\n", hr);
120 IDXGIFactory_Release(factory);
121 return hr;
123 break;
128 hr = D3D10CoreCreateDevice(factory, adapter, flags, NULL, device);
129 IDXGIAdapter_Release(adapter);
130 IDXGIFactory_Release(factory);
131 if (FAILED(hr))
133 WARN("Failed to create a device, returning %#x\n", hr);
134 return hr;
137 TRACE("Created ID3D10Device %p\n", *device);
139 return hr;
142 HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
143 HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc,
144 IDXGISwapChain **swapchain, ID3D10Device **device)
146 IDXGIDevice *dxgi_device;
147 IDXGIFactory *factory;
148 HRESULT hr;
150 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d,\n"
151 "\tswapchain_desc %p, swapchain %p, device %p\n",
152 adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version,
153 swapchain_desc, swapchain, device);
155 hr = D3D10CreateDevice(adapter, driver_type, swrast, flags, sdk_version, device);
156 if (FAILED(hr))
158 WARN("Failed to create a device, returning %#x\n", hr);
159 *device = NULL;
160 return hr;
163 TRACE("Created ID3D10Device %p\n", *device);
165 hr = ID3D10Device_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device);
166 if (FAILED(hr))
168 ERR("Failed to get a dxgi device from the d3d10 device, returning %#x\n", hr);
169 ID3D10Device_Release(*device);
170 *device = NULL;
171 return hr;
174 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
175 IDXGIDevice_Release(dxgi_device);
176 if (FAILED(hr))
178 ERR("Failed to get the device adapter, returning %#x\n", hr);
179 ID3D10Device_Release(*device);
180 *device = NULL;
181 return hr;
184 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
185 IDXGIAdapter_Release(adapter);
186 if (FAILED(hr))
188 ERR("Failed to get the adapter factory, returning %#x\n", hr);
189 ID3D10Device_Release(*device);
190 *device = NULL;
191 return hr;
194 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain);
195 IDXGIFactory_Release(factory);
196 if (FAILED(hr))
198 ID3D10Device_Release(*device);
199 *device = NULL;
201 WARN("Failed to create a swapchain, returning %#x\n", hr);
202 return hr;
205 TRACE("Created IDXGISwapChain %p\n", *swapchain);
207 return S_OK;
210 HRESULT WINAPI D3D10CreateEffectFromMemory(void *data, SIZE_T data_size, UINT flags,
211 ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3D10Effect **effect)
213 struct d3d10_effect *object;
214 HRESULT hr;
216 FIXME("data %p, data_size %lu, flags %#x, device %p, effect_pool %p, effect %p stub!\n",
217 data, data_size, flags, device, effect_pool, effect);
219 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
220 if (!object)
222 ERR("Failed to allocate D3D10 effect object memory\n");
223 return E_OUTOFMEMORY;
226 object->ID3D10Effect_iface.lpVtbl = &d3d10_effect_vtbl;
227 object->refcount = 1;
228 ID3D10Device_AddRef(device);
229 object->device = device;
231 hr = d3d10_effect_parse(object, data, data_size);
232 if (FAILED(hr))
234 ERR("Failed to parse effect\n");
235 IUnknown_Release(&object->ID3D10Effect_iface);
236 return hr;
239 *effect = &object->ID3D10Effect_iface;
241 TRACE("Created ID3D10Effect %p\n", object);
243 return S_OK;
246 HRESULT WINAPI D3D10CompileEffectFromMemory(void *data, SIZE_T data_size, const char *filename,
247 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, UINT hlsl_flags, UINT fx_flags,
248 ID3D10Blob **effect, ID3D10Blob **errors)
250 FIXME("data %p, data_size %lu, filename %s, defines %p, include %p,"
251 " hlsl_flags %#x, fx_flags %#x, effect %p, errors %p stub!\n",
252 data, data_size, wine_dbgstr_a(filename), defines, include,
253 hlsl_flags, fx_flags, effect, errors);
255 if (effect)
256 *effect = NULL;
257 if (errors)
258 *errors = NULL;
260 return E_NOTIMPL;
264 LPCSTR WINAPI D3D10GetVertexShaderProfile(ID3D10Device *device)
266 FIXME("device %p stub!\n", device);
268 return "vs_4_0";
271 LPCSTR WINAPI D3D10GetGeometryShaderProfile(ID3D10Device *device)
273 FIXME("device %p stub!\n", device);
275 return "gs_4_0";
278 LPCSTR WINAPI D3D10GetPixelShaderProfile(ID3D10Device *device)
280 FIXME("device %p stub!\n", device);
282 return "ps_4_0";
285 HRESULT WINAPI D3D10ReflectShader(const void *data, SIZE_T data_size, ID3D10ShaderReflection **reflector)
287 struct d3d10_shader_reflection *object;
289 FIXME("data %p, data_size %lu, reflector %p stub!\n", data, data_size, reflector);
291 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
292 if (!object)
294 ERR("Failed to allocate D3D10 shader reflection object memory\n");
295 return E_OUTOFMEMORY;
298 object->ID3D10ShaderReflection_iface.lpVtbl = &d3d10_shader_reflection_vtbl;
299 object->refcount = 1;
301 *reflector = &object->ID3D10ShaderReflection_iface;
303 TRACE("Created ID3D10ShaderReflection %p\n", object);
305 return S_OK;