1 | /*
|
---|
2 | * Direct3D wine internal interface main
|
---|
3 | *
|
---|
4 | * Copyright 2002-2003 The wine-d3d team
|
---|
5 | * Copyright 2002-2003 Raphael Junqueira
|
---|
6 | * Copyright 2004 Jason Edmeades
|
---|
7 | * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
---|
8 | * Copyright 2009 Henri Verbeet for CodeWeavers
|
---|
9 | *
|
---|
10 | * This library is free software; you can redistribute it and/or
|
---|
11 | * modify it under the terms of the GNU Lesser General Public
|
---|
12 | * License as published by the Free Software Foundation; either
|
---|
13 | * version 2.1 of the License, or (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This library is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | * Lesser General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU Lesser General Public
|
---|
21 | * License along with this library; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
23 | */
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
27 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
28 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
29 | * a choice of LGPL license versions is made available with the language indicating
|
---|
30 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
31 | * of the LGPL is applied is otherwise unspecified.
|
---|
32 | */
|
---|
33 |
|
---|
34 | #define VBOX_WINE_DEBUG_DEFINES
|
---|
35 |
|
---|
36 | #include "config.h"
|
---|
37 |
|
---|
38 | #include "initguid.h"
|
---|
39 | #include "wined3d_private.h"
|
---|
40 |
|
---|
41 | WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
---|
42 |
|
---|
43 | struct wined3d_wndproc
|
---|
44 | {
|
---|
45 | HWND window;
|
---|
46 | WNDPROC proc;
|
---|
47 | IWineD3DDeviceImpl *device;
|
---|
48 | };
|
---|
49 |
|
---|
50 | struct wined3d_wndproc_table
|
---|
51 | {
|
---|
52 | struct wined3d_wndproc *entries;
|
---|
53 | unsigned int count;
|
---|
54 | unsigned int size;
|
---|
55 | };
|
---|
56 |
|
---|
57 | static struct wined3d_wndproc_table wndproc_table;
|
---|
58 |
|
---|
59 | int num_lock = 0;
|
---|
60 | void (*CDECL wine_tsx11_lock_ptr)(void) = NULL;
|
---|
61 | void (*CDECL wine_tsx11_unlock_ptr)(void) = NULL;
|
---|
62 |
|
---|
63 | static CRITICAL_SECTION wined3d_cs;
|
---|
64 | static CRITICAL_SECTION_DEBUG wined3d_cs_debug =
|
---|
65 | {
|
---|
66 | 0, 0, &wined3d_cs,
|
---|
67 | {&wined3d_cs_debug.ProcessLocksList,
|
---|
68 | &wined3d_cs_debug.ProcessLocksList},
|
---|
69 | 0, 0, {(DWORD_PTR)(__FILE__ ": wined3d_cs")}
|
---|
70 | };
|
---|
71 | static CRITICAL_SECTION wined3d_cs = {&wined3d_cs_debug, -1, 0, 0, 0, 0};
|
---|
72 |
|
---|
73 | /* When updating default value here, make sure to update winecfg as well,
|
---|
74 | * where appropriate. */
|
---|
75 | wined3d_settings_t wined3d_settings =
|
---|
76 | {
|
---|
77 | VS_HW, /* Hardware by default */
|
---|
78 | PS_HW, /* Hardware by default */
|
---|
79 | TRUE, /* Use of GLSL enabled by default */
|
---|
80 | #ifdef VBOX_WITH_WDDM
|
---|
81 | ORM_FBO, /* Use FBO to do offscreen rendering */
|
---|
82 | #else
|
---|
83 | ORM_BACKBUFFER, /* Use backbuffer to do offscreen rendering */
|
---|
84 | #endif
|
---|
85 | RTL_READTEX, /* Default render target locking method */
|
---|
86 | PCI_VENDOR_NONE,/* PCI Vendor ID */
|
---|
87 | PCI_DEVICE_NONE,/* PCI Device ID */
|
---|
88 | 0, /* The default of memory is set in FillGLCaps */
|
---|
89 | NULL, /* No wine logo by default */
|
---|
90 | FALSE, /* Disable multisampling for now due to Nvidia driver bugs which happens for some users */
|
---|
91 | FALSE, /* No strict draw ordering. */
|
---|
92 | };
|
---|
93 |
|
---|
94 | IWineD3D * WINAPI WineDirect3DCreate(UINT version, IUnknown *parent)
|
---|
95 | {
|
---|
96 | IWineD3DImpl *object;
|
---|
97 | HRESULT hr;
|
---|
98 |
|
---|
99 | hr = VBoxExtCheckInit();
|
---|
100 | if (FAILED(hr))
|
---|
101 | {
|
---|
102 | ERR("VBoxExtCheckInit failed, hr (0x%x)\n", hr);
|
---|
103 | return NULL;
|
---|
104 | }
|
---|
105 |
|
---|
106 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
107 | if (!object)
|
---|
108 | {
|
---|
109 | ERR("Failed to allocate wined3d object memory.\n");
|
---|
110 | VBoxExtCheckTerm();
|
---|
111 | return NULL;
|
---|
112 | }
|
---|
113 |
|
---|
114 | hr = wined3d_init(object, version, parent);
|
---|
115 | if (FAILED(hr))
|
---|
116 | {
|
---|
117 | WARN("Failed to initialize wined3d object, hr %#x.\n", hr);
|
---|
118 | HeapFree(GetProcessHeap(), 0, object);
|
---|
119 | #ifdef VBOX_WITH_WDDM
|
---|
120 | VBoxExtCheckTerm();
|
---|
121 | #endif
|
---|
122 | return NULL;
|
---|
123 | }
|
---|
124 |
|
---|
125 | TRACE("Created wined3d object %p for d3d%d support.\n", object, version);
|
---|
126 |
|
---|
127 | return (IWineD3D *)object;
|
---|
128 | }
|
---|
129 |
|
---|
130 | static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
|
---|
131 | {
|
---|
132 | if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
|
---|
133 | if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
|
---|
134 | return ERROR_FILE_NOT_FOUND;
|
---|
135 | }
|
---|
136 |
|
---|
137 | static inline DWORD get_config_key_dword(HKEY defkey, HKEY appkey, const char* name, DWORD *data)
|
---|
138 | {
|
---|
139 | DWORD type;
|
---|
140 | DWORD size = sizeof(DWORD);
|
---|
141 | if (0 != appkey && !RegQueryValueExA( appkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
|
---|
142 | if (0 != defkey && !RegQueryValueExA( defkey, name, 0, &type, (LPBYTE) data, &size ) && (type == REG_DWORD)) return 0;
|
---|
143 | return ERROR_FILE_NOT_FOUND;
|
---|
144 | }
|
---|
145 |
|
---|
146 | static void CDECL wined3d_do_nothing(void)
|
---|
147 | {
|
---|
148 | }
|
---|
149 |
|
---|
150 | static void WINAPI wined3d_mutex_init(void)
|
---|
151 | {
|
---|
152 | InitializeCriticalSection(&wined3d_cs);
|
---|
153 | }
|
---|
154 |
|
---|
155 | static void WINAPI wined3d_mutex_term(void)
|
---|
156 | {
|
---|
157 | DeleteCriticalSection(&wined3d_cs);
|
---|
158 | }
|
---|
159 |
|
---|
160 | static BOOL wined3d_dll_init(HINSTANCE hInstDLL)
|
---|
161 | {
|
---|
162 | DWORD wined3d_context_tls_idx;
|
---|
163 | HMODULE mod;
|
---|
164 | char buffer[MAX_PATH+10];
|
---|
165 | DWORD size = sizeof(buffer);
|
---|
166 | HKEY hkey = 0;
|
---|
167 | HKEY appkey = 0;
|
---|
168 | DWORD len, tmpvalue;
|
---|
169 | WNDCLASSA wc;
|
---|
170 |
|
---|
171 | wined3d_mutex_init();
|
---|
172 |
|
---|
173 | wined3d_context_tls_idx = TlsAlloc();
|
---|
174 | if (wined3d_context_tls_idx == TLS_OUT_OF_INDEXES)
|
---|
175 | {
|
---|
176 | DWORD err = GetLastError();
|
---|
177 | ERR("Failed to allocate context TLS index, err %#x.\n", err);
|
---|
178 |
|
---|
179 | wined3d_mutex_term();
|
---|
180 | return FALSE;
|
---|
181 | }
|
---|
182 | context_set_tls_idx(wined3d_context_tls_idx);
|
---|
183 |
|
---|
184 | /* We need our own window class for a fake window which we use to retrieve GL capabilities */
|
---|
185 | /* We might need CS_OWNDC in the future if we notice strange things on Windows.
|
---|
186 | * Various articles/posts about OpenGL problems on Windows recommend this. */
|
---|
187 | wc.style = CS_HREDRAW | CS_VREDRAW;
|
---|
188 | wc.lpfnWndProc = DefWindowProcA;
|
---|
189 | wc.cbClsExtra = 0;
|
---|
190 | wc.cbWndExtra = 0;
|
---|
191 | wc.hInstance = hInstDLL;
|
---|
192 | wc.hIcon = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
|
---|
193 | wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
|
---|
194 | wc.hbrBackground = NULL;
|
---|
195 | wc.lpszMenuName = NULL;
|
---|
196 | wc.lpszClassName = WINED3D_OPENGL_WINDOW_CLASS_NAME;
|
---|
197 |
|
---|
198 | if (!RegisterClassA(&wc))
|
---|
199 | {
|
---|
200 | ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
|
---|
201 | if (!TlsFree(wined3d_context_tls_idx))
|
---|
202 | {
|
---|
203 | DWORD err = GetLastError();
|
---|
204 | ERR("Failed to free context TLS index, err %#x.\n", err);
|
---|
205 | }
|
---|
206 |
|
---|
207 | wined3d_mutex_term();
|
---|
208 |
|
---|
209 | return FALSE;
|
---|
210 | }
|
---|
211 |
|
---|
212 | DisableThreadLibraryCalls(hInstDLL);
|
---|
213 |
|
---|
214 | mod = GetModuleHandleA( "winex11.drv" );
|
---|
215 | if (mod)
|
---|
216 | {
|
---|
217 | wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
|
---|
218 | wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
|
---|
219 | }
|
---|
220 | else /* We are most likely on Windows */
|
---|
221 | {
|
---|
222 | wine_tsx11_lock_ptr = wined3d_do_nothing;
|
---|
223 | wine_tsx11_unlock_ptr = wined3d_do_nothing;
|
---|
224 | }
|
---|
225 | /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
|
---|
226 | if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
|
---|
227 |
|
---|
228 | len = GetModuleFileNameA( 0, buffer, MAX_PATH );
|
---|
229 | if (len && len < MAX_PATH)
|
---|
230 | {
|
---|
231 | HKEY tmpkey;
|
---|
232 | /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
|
---|
233 | if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
|
---|
234 | {
|
---|
235 | char *p, *appname = buffer;
|
---|
236 | if ((p = strrchr( appname, '/' ))) appname = p + 1;
|
---|
237 | if ((p = strrchr( appname, '\\' ))) appname = p + 1;
|
---|
238 | strcat( appname, "\\Direct3D" );
|
---|
239 | TRACE("appname = [%s]\n", appname);
|
---|
240 | if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
|
---|
241 | RegCloseKey( tmpkey );
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | if ( 0 != hkey || 0 != appkey )
|
---|
246 | {
|
---|
247 | if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
|
---|
248 | {
|
---|
249 | if (!strcmp(buffer,"none"))
|
---|
250 | {
|
---|
251 | TRACE("Disable vertex shaders\n");
|
---|
252 | wined3d_settings.vs_mode = VS_NONE;
|
---|
253 | }
|
---|
254 | }
|
---|
255 | if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
|
---|
256 | {
|
---|
257 | if (!strcmp(buffer,"enabled"))
|
---|
258 | {
|
---|
259 | TRACE("Allow pixel shaders\n");
|
---|
260 | wined3d_settings.ps_mode = PS_HW;
|
---|
261 | }
|
---|
262 | if (!strcmp(buffer,"disabled"))
|
---|
263 | {
|
---|
264 | TRACE("Disable pixel shaders\n");
|
---|
265 | wined3d_settings.ps_mode = PS_NONE;
|
---|
266 | }
|
---|
267 | }
|
---|
268 | if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
|
---|
269 | {
|
---|
270 | if (!strcmp(buffer,"disabled"))
|
---|
271 | {
|
---|
272 | TRACE("Use of GL Shading Language disabled\n");
|
---|
273 | wined3d_settings.glslRequested = FALSE;
|
---|
274 | }
|
---|
275 | }
|
---|
276 | if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
|
---|
277 | {
|
---|
278 | if (!strcmp(buffer,"backbuffer"))
|
---|
279 | {
|
---|
280 | TRACE("Using the backbuffer for offscreen rendering\n");
|
---|
281 | wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
|
---|
282 | }
|
---|
283 | else if (!strcmp(buffer,"fbo"))
|
---|
284 | {
|
---|
285 | TRACE("Using FBOs for offscreen rendering\n");
|
---|
286 | wined3d_settings.offscreen_rendering_mode = ORM_FBO;
|
---|
287 | }
|
---|
288 | }
|
---|
289 | if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
|
---|
290 | {
|
---|
291 | if (!strcmp(buffer,"disabled"))
|
---|
292 | {
|
---|
293 | TRACE("Disabling render target locking\n");
|
---|
294 | wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
|
---|
295 | }
|
---|
296 | else if (!strcmp(buffer,"readdraw"))
|
---|
297 | {
|
---|
298 | TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
|
---|
299 | wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
|
---|
300 | }
|
---|
301 | else if (!strcmp(buffer,"readtex"))
|
---|
302 | {
|
---|
303 | TRACE("Using glReadPixels for render target reading and textures for writing\n");
|
---|
304 | wined3d_settings.rendertargetlock_mode = RTL_READTEX;
|
---|
305 | }
|
---|
306 | }
|
---|
307 | if ( !get_config_key_dword( hkey, appkey, "VideoPciDeviceID", &tmpvalue) )
|
---|
308 | {
|
---|
309 | int pci_device_id = tmpvalue;
|
---|
310 |
|
---|
311 | /* A pci device id is 16-bit */
|
---|
312 | if(pci_device_id > 0xffff)
|
---|
313 | {
|
---|
314 | ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
|
---|
315 | }
|
---|
316 | else
|
---|
317 | {
|
---|
318 | TRACE("Using PCI Device ID %04x\n", pci_device_id);
|
---|
319 | wined3d_settings.pci_device_id = pci_device_id;
|
---|
320 | }
|
---|
321 | }
|
---|
322 | if ( !get_config_key_dword( hkey, appkey, "VideoPciVendorID", &tmpvalue) )
|
---|
323 | {
|
---|
324 | int pci_vendor_id = tmpvalue;
|
---|
325 |
|
---|
326 | /* A pci device id is 16-bit */
|
---|
327 | if(pci_vendor_id > 0xffff)
|
---|
328 | {
|
---|
329 | ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
|
---|
330 | }
|
---|
331 | else
|
---|
332 | {
|
---|
333 | TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
|
---|
334 | wined3d_settings.pci_vendor_id = pci_vendor_id;
|
---|
335 | }
|
---|
336 | }
|
---|
337 | if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
|
---|
338 | {
|
---|
339 | int TmpVideoMemorySize = atoi(buffer);
|
---|
340 | if(TmpVideoMemorySize > 0)
|
---|
341 | {
|
---|
342 | wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
|
---|
343 | TRACE("Use %iMB = %d byte for emulated_textureram\n",
|
---|
344 | TmpVideoMemorySize,
|
---|
345 | wined3d_settings.emulated_textureram);
|
---|
346 | }
|
---|
347 | else
|
---|
348 | ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
|
---|
349 | }
|
---|
350 | if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
|
---|
351 | {
|
---|
352 | size_t len = strlen(buffer) + 1;
|
---|
353 |
|
---|
354 | wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, len);
|
---|
355 | if (!wined3d_settings.logo) ERR("Failed to allocate logo path memory.\n");
|
---|
356 | else memcpy(wined3d_settings.logo, buffer, len);
|
---|
357 | }
|
---|
358 | if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
|
---|
359 | {
|
---|
360 | if (!strcmp(buffer,"enabled"))
|
---|
361 | {
|
---|
362 | TRACE("Allow multisampling\n");
|
---|
363 | wined3d_settings.allow_multisampling = TRUE;
|
---|
364 | }
|
---|
365 | }
|
---|
366 | if (!get_config_key(hkey, appkey, "StrictDrawOrdering", buffer, size)
|
---|
367 | && !strcmp(buffer,"enabled"))
|
---|
368 | {
|
---|
369 | TRACE("Enforcing strict draw ordering.\n");
|
---|
370 | wined3d_settings.strict_draw_ordering = TRUE;
|
---|
371 | }
|
---|
372 | }
|
---|
373 | if (wined3d_settings.vs_mode == VS_HW)
|
---|
374 | TRACE("Allow HW vertex shaders\n");
|
---|
375 | if (wined3d_settings.ps_mode == PS_NONE)
|
---|
376 | TRACE("Disable pixel shaders\n");
|
---|
377 | if (wined3d_settings.glslRequested)
|
---|
378 | TRACE("If supported by your system, GL Shading Language will be used\n");
|
---|
379 |
|
---|
380 | if (appkey) RegCloseKey( appkey );
|
---|
381 | if (hkey) RegCloseKey( hkey );
|
---|
382 |
|
---|
383 | return TRUE;
|
---|
384 | }
|
---|
385 |
|
---|
386 | static BOOL wined3d_dll_destroy(HINSTANCE hInstDLL)
|
---|
387 | {
|
---|
388 | DWORD wined3d_context_tls_idx = context_get_tls_idx();
|
---|
389 | unsigned int i;
|
---|
390 |
|
---|
391 | if (!TlsFree(wined3d_context_tls_idx))
|
---|
392 | {
|
---|
393 | DWORD err = GetLastError();
|
---|
394 | ERR("Failed to free context TLS index, err %#x.\n", err);
|
---|
395 | }
|
---|
396 |
|
---|
397 | for (i = 0; i < wndproc_table.count; ++i)
|
---|
398 | {
|
---|
399 | struct wined3d_wndproc *entry = &wndproc_table.entries[i];
|
---|
400 | SetWindowLongPtrW(entry->window, GWLP_WNDPROC, (LONG_PTR)entry->proc);
|
---|
401 | }
|
---|
402 | HeapFree(GetProcessHeap(), 0, wndproc_table.entries);
|
---|
403 |
|
---|
404 | HeapFree(GetProcessHeap(), 0, wined3d_settings.logo);
|
---|
405 | UnregisterClassA(WINED3D_OPENGL_WINDOW_CLASS_NAME, hInstDLL);
|
---|
406 |
|
---|
407 | wined3d_mutex_term();
|
---|
408 |
|
---|
409 | return TRUE;
|
---|
410 | }
|
---|
411 |
|
---|
412 | void WINAPI wined3d_mutex_lock(void)
|
---|
413 | {
|
---|
414 | EnterCriticalSection(&wined3d_cs);
|
---|
415 | }
|
---|
416 |
|
---|
417 | void WINAPI wined3d_mutex_unlock(void)
|
---|
418 | {
|
---|
419 | LeaveCriticalSection(&wined3d_cs);
|
---|
420 | }
|
---|
421 |
|
---|
422 | #ifndef VBOX_WITH_WDDM
|
---|
423 | static struct wined3d_wndproc *wined3d_find_wndproc(HWND window)
|
---|
424 | {
|
---|
425 | unsigned int i;
|
---|
426 |
|
---|
427 | for (i = 0; i < wndproc_table.count; ++i)
|
---|
428 | {
|
---|
429 | if (wndproc_table.entries[i].window == window)
|
---|
430 | {
|
---|
431 | return &wndproc_table.entries[i];
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | return NULL;
|
---|
436 | }
|
---|
437 |
|
---|
438 | static LRESULT CALLBACK wined3d_wndproc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
|
---|
439 | {
|
---|
440 | struct wined3d_wndproc *entry;
|
---|
441 | IWineD3DDeviceImpl *device;
|
---|
442 | WNDPROC proc;
|
---|
443 |
|
---|
444 | wined3d_mutex_lock();
|
---|
445 | entry = wined3d_find_wndproc(window);
|
---|
446 |
|
---|
447 | if (!entry)
|
---|
448 | {
|
---|
449 | wined3d_mutex_unlock();
|
---|
450 | ERR("Window %p is not registered with wined3d.\n", window);
|
---|
451 | return DefWindowProcW(window, message, wparam, lparam);
|
---|
452 | }
|
---|
453 |
|
---|
454 | device = entry->device;
|
---|
455 | proc = entry->proc;
|
---|
456 | wined3d_mutex_unlock();
|
---|
457 |
|
---|
458 | return device_process_message(device, window, message, wparam, lparam, proc);
|
---|
459 | }
|
---|
460 |
|
---|
461 | BOOL wined3d_register_window(HWND window, IWineD3DDeviceImpl *device)
|
---|
462 | {
|
---|
463 | struct wined3d_wndproc *entry;
|
---|
464 |
|
---|
465 | wined3d_mutex_lock();
|
---|
466 |
|
---|
467 | if (wndproc_table.size == wndproc_table.count)
|
---|
468 | {
|
---|
469 | unsigned int new_size = max(1, wndproc_table.size * 2);
|
---|
470 | struct wined3d_wndproc *new_entries;
|
---|
471 |
|
---|
472 | if (!wndproc_table.entries) new_entries = HeapAlloc(GetProcessHeap(), 0, new_size * sizeof(*new_entries));
|
---|
473 | else new_entries = HeapReAlloc(GetProcessHeap(), 0, wndproc_table.entries, new_size * sizeof(*new_entries));
|
---|
474 |
|
---|
475 | if (!new_entries)
|
---|
476 | {
|
---|
477 | wined3d_mutex_unlock();
|
---|
478 | ERR("Failed to grow table.\n");
|
---|
479 | return FALSE;
|
---|
480 | }
|
---|
481 |
|
---|
482 | wndproc_table.entries = new_entries;
|
---|
483 | wndproc_table.size = new_size;
|
---|
484 | }
|
---|
485 |
|
---|
486 | entry = &wndproc_table.entries[wndproc_table.count++];
|
---|
487 | entry->window = window;
|
---|
488 | entry->proc = (WNDPROC)SetWindowLongPtrW(window, GWLP_WNDPROC, (LONG_PTR)wined3d_wndproc);
|
---|
489 | entry->device = device;
|
---|
490 |
|
---|
491 | wined3d_mutex_unlock();
|
---|
492 |
|
---|
493 | return TRUE;
|
---|
494 | }
|
---|
495 |
|
---|
496 | void wined3d_unregister_window(HWND window)
|
---|
497 | {
|
---|
498 | unsigned int i;
|
---|
499 |
|
---|
500 | wined3d_mutex_lock();
|
---|
501 | for (i = 0; i < wndproc_table.count; ++i)
|
---|
502 | {
|
---|
503 | if (wndproc_table.entries[i].window == window)
|
---|
504 | {
|
---|
505 | struct wined3d_wndproc *entry = &wndproc_table.entries[i];
|
---|
506 | struct wined3d_wndproc *last = &wndproc_table.entries[--wndproc_table.count];
|
---|
507 |
|
---|
508 | if (GetWindowLongPtrW(window, GWLP_WNDPROC) == (LONG_PTR)wined3d_wndproc)
|
---|
509 | SetWindowLongPtrW(window, GWLP_WNDPROC, (LONG_PTR)entry->proc);
|
---|
510 | if (entry != last) *entry = *last;
|
---|
511 | wined3d_mutex_unlock();
|
---|
512 |
|
---|
513 | return;
|
---|
514 | }
|
---|
515 | }
|
---|
516 | wined3d_mutex_unlock();
|
---|
517 |
|
---|
518 | ERR("Window %p is not registered with wined3d.\n", window);
|
---|
519 | }
|
---|
520 | #endif
|
---|
521 | /* At process attach */
|
---|
522 | BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
|
---|
523 | {
|
---|
524 | TRACE("WineD3D DLLMain Reason=%u\n", fdwReason);
|
---|
525 |
|
---|
526 | switch (fdwReason)
|
---|
527 | {
|
---|
528 | case DLL_PROCESS_ATTACH:
|
---|
529 | return wined3d_dll_init(hInstDLL);
|
---|
530 |
|
---|
531 | case DLL_PROCESS_DETACH:
|
---|
532 | return wined3d_dll_destroy(hInstDLL);
|
---|
533 |
|
---|
534 | case DLL_THREAD_DETACH:
|
---|
535 | {
|
---|
536 | #if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
|
---|
537 | context_clear_on_thread_detach();
|
---|
538 | #else
|
---|
539 | if (!context_set_current(NULL))
|
---|
540 | {
|
---|
541 | ERR("Failed to clear current context.\n");
|
---|
542 | }
|
---|
543 | #endif
|
---|
544 | return TRUE;
|
---|
545 | }
|
---|
546 |
|
---|
547 | default:
|
---|
548 | return TRUE;
|
---|
549 | }
|
---|
550 | }
|
---|