winhttp: Only set the scheme if we have a valid URL.
[wine/multimedia.git] / dlls / dxgi / dxgi_main.c
blob3414c4f16be79a0563569ffdfdb79aafa565aeb6
1 /*
2 * Copyright 2008 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 "config.h"
21 #include "wine/port.h"
23 #define DXGI_INIT_GUID
24 #include "dxgi_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
28 static CRITICAL_SECTION_DEBUG dxgi_cs_debug =
30 0, 0, &dxgi_cs,
31 {&dxgi_cs_debug.ProcessLocksList,
32 &dxgi_cs_debug.ProcessLocksList},
33 0, 0, {(DWORD_PTR)(__FILE__ ": dxgi_cs")}
35 CRITICAL_SECTION dxgi_cs = {&dxgi_cs_debug, -1, 0, 0, 0, 0};
37 struct dxgi_main
39 HMODULE d3d10core;
40 struct dxgi_device_layer *device_layers;
41 UINT layer_count;
43 static struct dxgi_main dxgi_main;
45 static void dxgi_main_cleanup(void)
47 HeapFree(GetProcessHeap(), 0, dxgi_main.device_layers);
48 FreeLibrary(dxgi_main.d3d10core);
49 DeleteCriticalSection(&dxgi_cs);
52 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
54 switch (reason)
56 case DLL_PROCESS_ATTACH:
57 DisableThreadLibraryCalls(inst);
58 break;
60 case DLL_PROCESS_DETACH:
61 if (!reserved)
62 dxgi_main_cleanup();
63 break;
66 return TRUE;
69 HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void **factory)
71 TRACE("riid %s, factory %p\n", debugstr_guid(riid), factory);
73 return dxgi_factory_create(riid, factory, TRUE);
76 HRESULT WINAPI CreateDXGIFactory(REFIID riid, void **factory)
78 TRACE("riid %s, factory %p\n", debugstr_guid(riid), factory);
80 return dxgi_factory_create(riid, factory, FALSE);
83 static BOOL get_layer(enum dxgi_device_layer_id id, struct dxgi_device_layer *layer)
85 UINT i;
87 EnterCriticalSection(&dxgi_cs);
89 for (i = 0; i < dxgi_main.layer_count; ++i)
91 if (dxgi_main.device_layers[i].id == id)
93 *layer = dxgi_main.device_layers[i];
94 LeaveCriticalSection(&dxgi_cs);
95 return TRUE;
99 LeaveCriticalSection(&dxgi_cs);
100 return FALSE;
103 static HRESULT register_d3d10core_layers(HMODULE d3d10core)
105 EnterCriticalSection(&dxgi_cs);
107 if (!dxgi_main.d3d10core)
109 HRESULT hr;
110 HRESULT (WINAPI *d3d10core_register_layers)(void);
111 HMODULE mod;
112 BOOL ret;
114 if (!(ret = GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const char *)d3d10core, &mod)))
116 LeaveCriticalSection(&dxgi_cs);
117 return E_FAIL;
120 d3d10core_register_layers = (void *)GetProcAddress(mod, "D3D10CoreRegisterLayers");
121 hr = d3d10core_register_layers();
122 if (FAILED(hr))
124 ERR("Failed to register d3d10core layers, returning %#x\n", hr);
125 LeaveCriticalSection(&dxgi_cs);
126 return hr;
129 dxgi_main.d3d10core = mod;
132 LeaveCriticalSection(&dxgi_cs);
134 return S_OK;
137 HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory, IDXGIAdapter *adapter,
138 UINT flags, void *unknown0, void **device)
140 struct layer_get_size_args get_size_args;
141 struct dxgi_device *dxgi_device;
142 struct dxgi_device_layer d3d10_layer;
143 UINT device_size;
144 DWORD count;
145 HRESULT hr;
147 TRACE("d3d10core %p, factory %p, adapter %p, flags %#x, unknown0 %p, device %p.\n",
148 d3d10core, factory, adapter, flags, unknown0, device);
150 hr = register_d3d10core_layers(d3d10core);
151 if (FAILED(hr))
153 ERR("Failed to register d3d10core layers, returning %#x\n", hr);
154 return hr;
157 if (!get_layer(DXGI_DEVICE_LAYER_D3D10_DEVICE, &d3d10_layer))
159 ERR("Failed to get D3D10 device layer\n");
160 return E_FAIL;
163 count = 0;
164 hr = d3d10_layer.init(d3d10_layer.id, &count, NULL);
165 if (FAILED(hr))
167 WARN("Failed to initialize D3D10 device layer\n");
168 return E_FAIL;
171 get_size_args.unknown0 = 0;
172 get_size_args.unknown1 = 0;
173 get_size_args.unknown2 = NULL;
174 get_size_args.unknown3 = NULL;
175 get_size_args.adapter = adapter;
176 get_size_args.interface_major = 10;
177 get_size_args.interface_minor = 1;
178 get_size_args.version_build = 4;
179 get_size_args.version_revision = 6000;
181 device_size = d3d10_layer.get_size(d3d10_layer.id, &get_size_args, 0);
182 device_size += sizeof(*dxgi_device);
184 dxgi_device = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, device_size);
185 if (!dxgi_device)
187 ERR("Failed to allocate device memory\n");
188 return E_OUTOFMEMORY;
191 hr = dxgi_device_init(dxgi_device, &d3d10_layer, factory, adapter);
192 if (FAILED(hr))
194 WARN("Failed to initialize device, hr %#x.\n", hr);
195 HeapFree(GetProcessHeap(), 0, dxgi_device);
196 *device = NULL;
197 return hr;
200 TRACE("Created device %p.\n", dxgi_device);
201 *device = dxgi_device;
203 return S_OK;
206 HRESULT WINAPI DXGID3D10RegisterLayers(const struct dxgi_device_layer *layers, UINT layer_count)
208 UINT i;
209 struct dxgi_device_layer *new_layers;
211 TRACE("layers %p, layer_count %u\n", layers, layer_count);
213 EnterCriticalSection(&dxgi_cs);
215 if (!dxgi_main.layer_count)
216 new_layers = HeapAlloc(GetProcessHeap(), 0, layer_count * sizeof(*new_layers));
217 else
218 new_layers = HeapReAlloc(GetProcessHeap(), 0, dxgi_main.device_layers,
219 (dxgi_main.layer_count + layer_count) * sizeof(*new_layers));
221 if (!new_layers)
223 LeaveCriticalSection(&dxgi_cs);
224 ERR("Failed to allocate layer memory\n");
225 return E_OUTOFMEMORY;
228 for (i = 0; i < layer_count; ++i)
230 const struct dxgi_device_layer *layer = &layers[i];
232 TRACE("layer %d: id %#x, init %p, get_size %p, create %p\n",
233 i, layer->id, layer->init, layer->get_size, layer->create);
235 new_layers[dxgi_main.layer_count + i] = *layer;
238 dxgi_main.device_layers = new_layers;
239 dxgi_main.layer_count += layer_count;
241 LeaveCriticalSection(&dxgi_cs);
243 return S_OK;