ReactOS 0.4.17-dev-934-g091855f
dxgi_main.c
Go to the documentation of this file.
1/*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 *
18 */
19
20#define DXGI_INIT_GUID
21#include "dxgi_private.h"
22
24
26{
30};
31static struct dxgi_main dxgi_main;
32
33static void dxgi_main_cleanup(void)
34{
37}
38
40{
41 switch (reason)
42 {
45 break;
46
48 if (!reserved)
50 break;
51 }
52
53 return TRUE;
54}
55
57{
58 TRACE("flags %#x, iid %s, factory %p.\n", flags, debugstr_guid(iid), factory);
59
60 if (flags)
61 FIXME("Ignoring flags %#x.\n", flags);
62
63 return dxgi_factory_create(iid, factory, TRUE);
64}
65
67{
68 TRACE("iid %s, factory %p.\n", debugstr_guid(iid), factory);
69
70 return dxgi_factory_create(iid, factory, TRUE);
71}
72
74{
75 TRACE("iid %s, factory %p.\n", debugstr_guid(iid), factory);
76
77 return dxgi_factory_create(iid, factory, FALSE);
78}
79
81{
82 UINT i;
83
85
86 for (i = 0; i < dxgi_main.layer_count; ++i)
87 {
88 if (dxgi_main.device_layers[i].id == id)
89 {
92 return TRUE;
93 }
94 }
95
97 return FALSE;
98}
99
101{
103
104 if (!dxgi_main.d3d10core)
105 {
106 HRESULT hr;
107 HRESULT (WINAPI *d3d11core_register_layers)(void);
108 HMODULE mod;
109 BOOL ret;
110
111 if (!(ret = GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const char *)d3d10core, &mod)))
112 {
114 return E_FAIL;
115 }
116
117 d3d11core_register_layers = (void *)GetProcAddress(mod, "D3D11CoreRegisterLayers");
118 hr = d3d11core_register_layers();
119 if (FAILED(hr))
120 {
121 ERR("Failed to register d3d11 layers, returning %#lx.\n", hr);
124 return hr;
125 }
126
128 }
129
131
132 return S_OK;
133}
134
136 unsigned int flags, const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count, void **device)
137{
138 struct layer_get_size_args get_size_args;
139 struct dxgi_device_layer d3d10_layer;
140 struct dxgi_device *dxgi_device;
141 UINT device_size;
142 DWORD count;
143 HRESULT hr;
144
145 TRACE("d3d10core %p, factory %p, adapter %p, flags %#x, feature_levels %p, level_count %u, device %p.\n",
146 d3d10core, factory, adapter, flags, feature_levels, level_count, device);
147
148 if (flags)
149 FIXME("Ignoring flags %#x.\n", flags);
150
151 if (TRACE_ON(dxgi))
153
154 hr = register_d3d10core_layers(d3d10core);
155 if (FAILED(hr))
156 {
157 ERR("Failed to register d3d10core layers, returning %#lx.\n", hr);
158 return hr;
159 }
160
161 if (!get_layer(DXGI_DEVICE_LAYER_D3D10_DEVICE, &d3d10_layer))
162 {
163 ERR("Failed to get D3D10 device layer.\n");
164 return E_FAIL;
165 }
166
167 count = 0;
168 hr = d3d10_layer.init(d3d10_layer.id, &count, NULL);
169 if (FAILED(hr))
170 {
171 WARN("Failed to initialize D3D10 device layer.\n");
172 return E_FAIL;
173 }
174
175 get_size_args.unknown0 = 0;
176 get_size_args.unknown1 = 0;
177 get_size_args.unknown2 = NULL;
178 get_size_args.unknown3 = NULL;
179 get_size_args.adapter = adapter;
180 get_size_args.interface_major = 10;
181 get_size_args.interface_minor = 1;
182 get_size_args.version_build = 4;
183 get_size_args.version_revision = 6000;
184
185 device_size = d3d10_layer.get_size(d3d10_layer.id, &get_size_args, 0);
186 device_size += sizeof(*dxgi_device);
187
188 if (!(dxgi_device = calloc(1, device_size)))
189 {
190 ERR("Failed to allocate device memory.\n");
191 return E_OUTOFMEMORY;
192 }
193
194 hr = dxgi_device_init(dxgi_device, &d3d10_layer, factory, adapter, feature_levels, level_count);
195 if (FAILED(hr))
196 {
197 WARN("Failed to initialize device, hr %#lx.\n", hr);
199 *device = NULL;
200 return hr;
201 }
202
203 TRACE("Created device %p.\n", dxgi_device);
205
206 return S_OK;
207}
208
210{
211 UINT i;
212 struct dxgi_device_layer *new_layers;
213
214 TRACE("layers %p, layer_count %u\n", layers, layer_count);
215
217
218 new_layers = realloc(dxgi_main.device_layers,
219 (dxgi_main.layer_count + layer_count) * sizeof(*new_layers));
220
221 if (!new_layers)
222 {
224 ERR("Failed to allocate layer memory\n");
225 return E_OUTOFMEMORY;
226 }
227
228 for (i = 0; i < layer_count; ++i)
229 {
230 const struct dxgi_device_layer *layer = &layers[i];
231
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);
234
235 new_layers[dxgi_main.layer_count + i] = *layer;
236 }
237
238 dxgi_main.device_layers = new_layers;
239 dxgi_main.layer_count += layer_count;
240
242
243 return S_OK;
244}
245
247{
248 TRACE("flags %#x, iid %s, debug %p.\n", flags, debugstr_guid(iid), debug);
249
250 WARN("Returning DXGI_ERROR_SDK_COMPONENT_MISSING.\n");
252}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:68
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
dxgi_device_layer_id
@ DXGI_DEVICE_LAYER_D3D10_DEVICE
D3D_FEATURE_LEVEL
Definition: d3dcommon.idl:102
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HRESULT dxgi_device_init(struct dxgi_device *device, struct dxgi_device_layer *layer, IDXGIFactory *factory, IDXGIAdapter *adapter, const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count)
Definition: device.c:486
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1971
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define TRACE_ON(x)
Definition: compat.h:75
BOOL WINAPI GetModuleHandleExA(IN DWORD dwFlags, IN LPCSTR lpModuleName OPTIONAL, OUT HMODULE *phModule)
Definition: loader.c:896
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
return ret
Definition: mutex.c:147
r reserved
Definition: btrfs.c:3006
HRESULT WINAPI CreateDXGIFactory1(REFIID iid, void **factory)
Definition: dxgi_main.c:66
static HRESULT register_d3d10core_layers(HMODULE d3d10core)
Definition: dxgi_main.c:100
HRESULT WINAPI DXGID3D10RegisterLayers(const struct dxgi_device_layer *layers, UINT layer_count)
Definition: dxgi_main.c:209
HRESULT WINAPI CreateDXGIFactory(REFIID iid, void **factory)
Definition: dxgi_main.c:73
HRESULT WINAPI DXGIGetDebugInterface1(UINT flags, REFIID iid, void **debug)
Definition: dxgi_main.c:246
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
Definition: dxgi_main.c:39
static BOOL get_layer(enum dxgi_device_layer_id id, struct dxgi_device_layer *layer)
Definition: dxgi_main.c:80
HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory, IDXGIAdapter *adapter, unsigned int flags, const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count, void **device)
Definition: dxgi_main.c:135
static void dxgi_main_cleanup(void)
Definition: dxgi_main.c:33
HRESULT WINAPI CreateDXGIFactory2(UINT flags, REFIID iid, void **factory)
Definition: dxgi_main.c:56
void dump_feature_levels(const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count)
Definition: utils.c:410
HRESULT dxgi_factory_create(REFIID riid, void **factory, BOOL extended)
Definition: factory.c:585
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
return adapter
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLbitfield flags
Definition: glext.h:7161
GLenum GLuint GLint GLint layer
Definition: glext.h:7007
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: sysinfo.c:13
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL * feature_levels
Definition: hlsl_d3d11.c:28
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
#define debug(msg)
Definition: key_call.c:71
#define REFIID
Definition: guiddef.h:118
#define calloc
Definition: rosglue.h:14
#define TRACE(s)
Definition: solgame.cpp:4
Definition: devices.h:37
enum dxgi_device_layer_id id
IWineDXGIDevice IWineDXGIDevice_iface
Definition: dxgi_private.h:129
UINT layer_count
Definition: dxgi_main.c:29
HMODULE d3d10core
Definition: dxgi_main.c:27
struct dxgi_device_layer * device_layers
Definition: dxgi_main.c:28
Definition: main.c:439
IDXGIAdapter * adapter
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539
#define DXGI_ERROR_SDK_COMPONENT_MISSING
Definition: winerror.h:7151