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