wined3d: Use the texture dimension helpers in wined3d_texture_update_overlay().
[wine.git] / dlls / dxgi / dxgi_main.c
bloba4c1362e80c25a7981388399c47ddb6b3711416f
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 wined3d_mutex_unlock();
116 return hr;
119 dxgi_main.d3d10core = mod;
122 wined3d_mutex_unlock();
124 return S_OK;
127 HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory, IDXGIAdapter *adapter,
128 unsigned int flags, const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count, void **device)
130 struct layer_get_size_args get_size_args;
131 struct dxgi_device *dxgi_device;
132 struct dxgi_device_layer d3d10_layer;
133 UINT device_size;
134 DWORD count;
135 HRESULT hr;
137 TRACE("d3d10core %p, factory %p, adapter %p, flags %#x, feature_levels %p, level_count %u, device %p.\n",
138 d3d10core, factory, adapter, flags, feature_levels, level_count, device);
140 FIXME("Ignoring flags.\n");
142 hr = register_d3d10core_layers(d3d10core);
143 if (FAILED(hr))
145 ERR("Failed to register d3d10core layers, returning %#x\n", hr);
146 return hr;
149 if (!get_layer(DXGI_DEVICE_LAYER_D3D10_DEVICE, &d3d10_layer))
151 ERR("Failed to get D3D10 device layer\n");
152 return E_FAIL;
155 count = 0;
156 hr = d3d10_layer.init(d3d10_layer.id, &count, NULL);
157 if (FAILED(hr))
159 WARN("Failed to initialize D3D10 device layer\n");
160 return E_FAIL;
163 get_size_args.unknown0 = 0;
164 get_size_args.unknown1 = 0;
165 get_size_args.unknown2 = NULL;
166 get_size_args.unknown3 = NULL;
167 get_size_args.adapter = adapter;
168 get_size_args.interface_major = 10;
169 get_size_args.interface_minor = 1;
170 get_size_args.version_build = 4;
171 get_size_args.version_revision = 6000;
173 device_size = d3d10_layer.get_size(d3d10_layer.id, &get_size_args, 0);
174 device_size += sizeof(*dxgi_device);
176 dxgi_device = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, device_size);
177 if (!dxgi_device)
179 ERR("Failed to allocate device memory\n");
180 return E_OUTOFMEMORY;
183 hr = dxgi_device_init(dxgi_device, &d3d10_layer, factory, adapter, feature_levels, level_count);
184 if (FAILED(hr))
186 WARN("Failed to initialize device, hr %#x.\n", hr);
187 HeapFree(GetProcessHeap(), 0, dxgi_device);
188 *device = NULL;
189 return hr;
192 TRACE("Created device %p.\n", dxgi_device);
193 *device = dxgi_device;
195 return S_OK;
198 HRESULT WINAPI DXGID3D10RegisterLayers(const struct dxgi_device_layer *layers, UINT layer_count)
200 UINT i;
201 struct dxgi_device_layer *new_layers;
203 TRACE("layers %p, layer_count %u\n", layers, layer_count);
205 wined3d_mutex_lock();
207 if (!dxgi_main.layer_count)
208 new_layers = HeapAlloc(GetProcessHeap(), 0, layer_count * sizeof(*new_layers));
209 else
210 new_layers = HeapReAlloc(GetProcessHeap(), 0, dxgi_main.device_layers,
211 (dxgi_main.layer_count + layer_count) * sizeof(*new_layers));
213 if (!new_layers)
215 wined3d_mutex_unlock();
216 ERR("Failed to allocate layer memory\n");
217 return E_OUTOFMEMORY;
220 for (i = 0; i < layer_count; ++i)
222 const struct dxgi_device_layer *layer = &layers[i];
224 TRACE("layer %d: id %#x, init %p, get_size %p, create %p\n",
225 i, layer->id, layer->init, layer->get_size, layer->create);
227 new_layers[dxgi_main.layer_count + i] = *layer;
230 dxgi_main.device_layers = new_layers;
231 dxgi_main.layer_count += layer_count;
233 wined3d_mutex_unlock();
235 return S_OK;