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
21 #include "wine/port.h"
23 #define DXGI_INIT_GUID
24 #include "dxgi_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dxgi
);
31 struct dxgi_device_layer
*device_layers
;
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
)
46 case DLL_PROCESS_ATTACH
:
47 DisableThreadLibraryCalls(inst
);
50 case DLL_PROCESS_DETACH
:
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
)
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();
89 wined3d_mutex_unlock();
93 static HRESULT
register_d3d10core_layers(HMODULE d3d10core
)
97 if (!dxgi_main
.d3d10core
)
100 HRESULT (WINAPI
*d3d11core_register_layers
)(void);
104 if (!(ret
= GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (const char *)d3d10core
, &mod
)))
106 wined3d_mutex_unlock();
110 d3d11core_register_layers
= (void *)GetProcAddress(mod
, "D3D11CoreRegisterLayers");
111 hr
= d3d11core_register_layers();
114 ERR("Failed to register d3d11 layers, returning %#x.\n", hr
);
116 wined3d_mutex_unlock();
120 dxgi_main
.d3d10core
= mod
;
123 wined3d_mutex_unlock();
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
;
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
);
142 FIXME("Ignoring flags %#x.\n", flags
);
145 dump_feature_levels(feature_levels
, level_count
);
147 hr
= register_d3d10core_layers(d3d10core
);
150 ERR("Failed to register d3d10core layers, returning %#x.\n", hr
);
154 if (!get_layer(DXGI_DEVICE_LAYER_D3D10_DEVICE
, &d3d10_layer
))
156 ERR("Failed to get D3D10 device layer.\n");
161 hr
= d3d10_layer
.init(d3d10_layer
.id
, &count
, NULL
);
164 WARN("Failed to initialize D3D10 device layer.\n");
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
);
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
);
191 WARN("Failed to initialize device, hr %#x.\n", hr
);
192 HeapFree(GetProcessHeap(), 0, dxgi_device
);
197 TRACE("Created device %p.\n", dxgi_device
);
198 *device
= &dxgi_device
->IWineDXGIDevice_iface
;
203 HRESULT WINAPI
DXGID3D10RegisterLayers(const struct dxgi_device_layer
*layers
, UINT layer_count
)
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
));
215 new_layers
= HeapReAlloc(GetProcessHeap(), 0, dxgi_main
.device_layers
,
216 (dxgi_main
.layer_count
+ layer_count
) * sizeof(*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();