regedit: Update the listview path when renaming a treeview node.
[wine.git] / dlls / dxgi / dxgi_main.c
blob60ff3c1260b63b1f252e2a7e2cf5858e3d517cff
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 struct dxgi_main
30 HMODULE d3d10core;
31 struct dxgi_device_layer *device_layers;
32 UINT layer_count;
34 static struct dxgi_main dxgi_main;
36 static void dxgi_main_cleanup(void)
38 HeapFree(GetProcessHeap(), 0, dxgi_main.device_layers);
39 FreeLibrary(dxgi_main.d3d10core);
42 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
44 switch (reason)
46 case DLL_PROCESS_ATTACH:
47 DisableThreadLibraryCalls(inst);
48 break;
50 case DLL_PROCESS_DETACH:
51 if (!reserved)
52 dxgi_main_cleanup();
53 break;
56 return TRUE;
59 HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void **factory)
61 TRACE("riid %s, factory %p\n", debugstr_guid(riid), factory);
63 return dxgi_factory_create(riid, factory, TRUE);
66 HRESULT WINAPI CreateDXGIFactory(REFIID riid, void **factory)
68 TRACE("riid %s, factory %p\n", debugstr_guid(riid), factory);
70 return dxgi_factory_create(riid, factory, FALSE);
73 static BOOL get_layer(enum dxgi_device_layer_id id, struct dxgi_device_layer *layer)
75 UINT i;
77 wined3d_mutex_lock();
79 for (i = 0; i < dxgi_main.layer_count; ++i)
81 if (dxgi_main.device_layers[i].id == id)
83 *layer = dxgi_main.device_layers[i];
84 wined3d_mutex_unlock();
85 return TRUE;
89 wined3d_mutex_unlock();
90 return FALSE;
93 static HRESULT register_d3d10core_layers(HMODULE d3d10core)
95 wined3d_mutex_lock();
97 if (!dxgi_main.d3d10core)
99 HRESULT hr;
100 HRESULT (WINAPI *d3d11core_register_layers)(void);
101 HMODULE mod;
102 BOOL ret;
104 if (!(ret = GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const char *)d3d10core, &mod)))
106 wined3d_mutex_unlock();
107 return E_FAIL;
110 d3d11core_register_layers = (void *)GetProcAddress(mod, "D3D11CoreRegisterLayers");
111 hr = d3d11core_register_layers();
112 if (FAILED(hr))
114 ERR("Failed to register d3d11 layers, returning %#x.\n", hr);
115 FreeLibrary(mod);
116 wined3d_mutex_unlock();
117 return hr;
120 dxgi_main.d3d10core = mod;
123 wined3d_mutex_unlock();
125 return S_OK;
128 HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory, IDXGIAdapter *adapter,
129 unsigned int flags, const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count, void **device)
131 struct layer_get_size_args get_size_args;
132 struct dxgi_device_layer d3d10_layer;
133 struct dxgi_device *dxgi_device;
134 UINT device_size;
135 DWORD count;
136 HRESULT hr;
138 TRACE("d3d10core %p, factory %p, adapter %p, flags %#x, feature_levels %p, level_count %u, device %p.\n",
139 d3d10core, factory, adapter, flags, feature_levels, level_count, device);
141 if (flags)
142 FIXME("Ignoring flags %#x.\n", flags);
144 if (TRACE_ON(dxgi))
145 dump_feature_levels(feature_levels, level_count);
147 hr = register_d3d10core_layers(d3d10core);
148 if (FAILED(hr))
150 ERR("Failed to register d3d10core layers, returning %#x.\n", hr);
151 return hr;
154 if (!get_layer(DXGI_DEVICE_LAYER_D3D10_DEVICE, &d3d10_layer))
156 ERR("Failed to get D3D10 device layer.\n");
157 return E_FAIL;
160 count = 0;
161 hr = d3d10_layer.init(d3d10_layer.id, &count, NULL);
162 if (FAILED(hr))
164 WARN("Failed to initialize D3D10 device layer.\n");
165 return E_FAIL;
168 get_size_args.unknown0 = 0;
169 get_size_args.unknown1 = 0;
170 get_size_args.unknown2 = NULL;
171 get_size_args.unknown3 = NULL;
172 get_size_args.adapter = adapter;
173 get_size_args.interface_major = 10;
174 get_size_args.interface_minor = 1;
175 get_size_args.version_build = 4;
176 get_size_args.version_revision = 6000;
178 device_size = d3d10_layer.get_size(d3d10_layer.id, &get_size_args, 0);
179 device_size += sizeof(*dxgi_device);
181 dxgi_device = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, device_size);
182 if (!dxgi_device)
184 ERR("Failed to allocate device memory.\n");
185 return E_OUTOFMEMORY;
188 hr = dxgi_device_init(dxgi_device, &d3d10_layer, factory, adapter, feature_levels, level_count);
189 if (FAILED(hr))
191 WARN("Failed to initialize device, hr %#x.\n", hr);
192 HeapFree(GetProcessHeap(), 0, dxgi_device);
193 *device = NULL;
194 return hr;
197 TRACE("Created device %p.\n", dxgi_device);
198 *device = &dxgi_device->IWineDXGIDevice_iface;
200 return S_OK;
203 HRESULT WINAPI DXGID3D10RegisterLayers(const struct dxgi_device_layer *layers, UINT layer_count)
205 UINT i;
206 struct dxgi_device_layer *new_layers;
208 TRACE("layers %p, layer_count %u\n", layers, layer_count);
210 wined3d_mutex_lock();
212 if (!dxgi_main.layer_count)
213 new_layers = HeapAlloc(GetProcessHeap(), 0, layer_count * sizeof(*new_layers));
214 else
215 new_layers = HeapReAlloc(GetProcessHeap(), 0, dxgi_main.device_layers,
216 (dxgi_main.layer_count + layer_count) * sizeof(*new_layers));
218 if (!new_layers)
220 wined3d_mutex_unlock();
221 ERR("Failed to allocate layer memory\n");
222 return E_OUTOFMEMORY;
225 for (i = 0; i < layer_count; ++i)
227 const struct dxgi_device_layer *layer = &layers[i];
229 TRACE("layer %d: id %#x, init %p, get_size %p, create %p\n",
230 i, layer->id, layer->init, layer->get_size, layer->create);
232 new_layers[dxgi_main.layer_count + i] = *layer;
235 dxgi_main.device_layers = new_layers;
236 dxgi_main.layer_count += layer_count;
238 wined3d_mutex_unlock();
240 return S_OK;