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 heap_free(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
CreateDXGIFactory2(UINT flags
, REFIID iid
, void **factory
)
61 TRACE("flags %#x, iid %s, factory %p.\n", flags
, debugstr_guid(iid
), factory
);
64 FIXME("Ignoring flags %#x.\n", flags
);
66 return dxgi_factory_create(iid
, factory
, TRUE
);
69 HRESULT WINAPI
CreateDXGIFactory1(REFIID iid
, void **factory
)
71 TRACE("iid %s, factory %p.\n", debugstr_guid(iid
), factory
);
73 return dxgi_factory_create(iid
, factory
, TRUE
);
76 HRESULT WINAPI
CreateDXGIFactory(REFIID iid
, void **factory
)
78 TRACE("iid %s, factory %p.\n", debugstr_guid(iid
), factory
);
80 return dxgi_factory_create(iid
, factory
, FALSE
);
83 static BOOL
get_layer(enum dxgi_device_layer_id id
, struct dxgi_device_layer
*layer
)
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 wined3d_mutex_unlock();
99 wined3d_mutex_unlock();
103 static HRESULT
register_d3d10core_layers(HMODULE d3d10core
)
105 wined3d_mutex_lock();
107 if (!dxgi_main
.d3d10core
)
110 HRESULT (WINAPI
*d3d11core_register_layers
)(void);
114 if (!(ret
= GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
, (const char *)d3d10core
, &mod
)))
116 wined3d_mutex_unlock();
120 d3d11core_register_layers
= (void *)GetProcAddress(mod
, "D3D11CoreRegisterLayers");
121 hr
= d3d11core_register_layers();
124 ERR("Failed to register d3d11 layers, returning %#x.\n", hr
);
126 wined3d_mutex_unlock();
130 dxgi_main
.d3d10core
= mod
;
133 wined3d_mutex_unlock();
138 HRESULT WINAPI
DXGID3D10CreateDevice(HMODULE d3d10core
, IDXGIFactory
*factory
, IDXGIAdapter
*adapter
,
139 unsigned int flags
, const D3D_FEATURE_LEVEL
*feature_levels
, unsigned int level_count
, void **device
)
141 struct layer_get_size_args get_size_args
;
142 struct dxgi_device_layer d3d10_layer
;
143 struct dxgi_device
*dxgi_device
;
148 TRACE("d3d10core %p, factory %p, adapter %p, flags %#x, feature_levels %p, level_count %u, device %p.\n",
149 d3d10core
, factory
, adapter
, flags
, feature_levels
, level_count
, device
);
152 FIXME("Ignoring flags %#x.\n", flags
);
155 dump_feature_levels(feature_levels
, level_count
);
157 hr
= register_d3d10core_layers(d3d10core
);
160 ERR("Failed to register d3d10core layers, returning %#x.\n", hr
);
164 if (!get_layer(DXGI_DEVICE_LAYER_D3D10_DEVICE
, &d3d10_layer
))
166 ERR("Failed to get D3D10 device layer.\n");
171 hr
= d3d10_layer
.init(d3d10_layer
.id
, &count
, NULL
);
174 WARN("Failed to initialize D3D10 device layer.\n");
178 get_size_args
.unknown0
= 0;
179 get_size_args
.unknown1
= 0;
180 get_size_args
.unknown2
= NULL
;
181 get_size_args
.unknown3
= NULL
;
182 get_size_args
.adapter
= adapter
;
183 get_size_args
.interface_major
= 10;
184 get_size_args
.interface_minor
= 1;
185 get_size_args
.version_build
= 4;
186 get_size_args
.version_revision
= 6000;
188 device_size
= d3d10_layer
.get_size(d3d10_layer
.id
, &get_size_args
, 0);
189 device_size
+= sizeof(*dxgi_device
);
191 if (!(dxgi_device
= heap_alloc_zero(device_size
)))
193 ERR("Failed to allocate device memory.\n");
194 return E_OUTOFMEMORY
;
197 hr
= dxgi_device_init(dxgi_device
, &d3d10_layer
, factory
, adapter
, feature_levels
, level_count
);
200 WARN("Failed to initialize device, hr %#x.\n", hr
);
201 heap_free(dxgi_device
);
206 TRACE("Created device %p.\n", dxgi_device
);
207 *device
= &dxgi_device
->IWineDXGIDevice_iface
;
212 HRESULT WINAPI
DXGID3D10RegisterLayers(const struct dxgi_device_layer
*layers
, UINT layer_count
)
215 struct dxgi_device_layer
*new_layers
;
217 TRACE("layers %p, layer_count %u\n", layers
, layer_count
);
219 wined3d_mutex_lock();
221 if (!dxgi_main
.layer_count
)
222 new_layers
= heap_alloc(layer_count
* sizeof(*new_layers
));
224 new_layers
= heap_realloc(dxgi_main
.device_layers
,
225 (dxgi_main
.layer_count
+ layer_count
) * sizeof(*new_layers
));
229 wined3d_mutex_unlock();
230 ERR("Failed to allocate layer memory\n");
231 return E_OUTOFMEMORY
;
234 for (i
= 0; i
< layer_count
; ++i
)
236 const struct dxgi_device_layer
*layer
= &layers
[i
];
238 TRACE("layer %d: id %#x, init %p, get_size %p, create %p\n",
239 i
, layer
->id
, layer
->init
, layer
->get_size
, layer
->create
);
241 new_layers
[dxgi_main
.layer_count
+ i
] = *layer
;
244 dxgi_main
.device_layers
= new_layers
;
245 dxgi_main
.layer_count
+= layer_count
;
247 wined3d_mutex_unlock();
252 HRESULT WINAPI
DXGIGetDebugInterface1(UINT flags
, REFIID iid
, void **debug
)
254 TRACE("flags %#x, iid %s, debug %p.\n", flags
, debugstr_guid(iid
), debug
);
256 WARN("Returning DXGI_ERROR_SDK_COMPONENT_MISSING.\n");
257 return DXGI_ERROR_SDK_COMPONENT_MISSING
;