VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c@ 38112

最後變更 在這個檔案從38112是 38112,由 vboxsync 提交於 14 年 前

wddm/3d: 1. fix invalid visible rectreporting on swapchain destruction 2. single context for wine (disabled so far), 3 wine & 3d driver bugfixes

  • 屬性 svn:eol-style 設為 native
檔案大小: 16.9 KB
 
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
39WINE_DEFAULT_DEBUG_CHANNEL(d3d);
40
41struct wined3d_wndproc
42{
43 HWND window;
44 WNDPROC proc;
45 IWineD3DDeviceImpl *device;
46};
47
48struct wined3d_wndproc_table
49{
50 struct wined3d_wndproc *entries;
51 unsigned int count;
52 unsigned int size;
53};
54
55static struct wined3d_wndproc_table wndproc_table;
56
57int num_lock = 0;
58void (*CDECL wine_tsx11_lock_ptr)(void) = NULL;
59void (*CDECL wine_tsx11_unlock_ptr)(void) = NULL;
60
61static CRITICAL_SECTION wined3d_cs;
62static 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};
69static 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. */
73wined3d_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
92IWineD3D * 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
132static 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
139static 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
148static void CDECL wined3d_do_nothing(void)
149{
150}
151
152static BOOL wined3d_dll_init(HINSTANCE hInstDLL)
153{
154 DWORD wined3d_context_tls_idx;
155 HMODULE mod;
156 char buffer[MAX_PATH+10];
157 DWORD size = sizeof(buffer);
158 HKEY hkey = 0;
159 HKEY appkey = 0;
160 DWORD len, tmpvalue;
161 WNDCLASSA wc;
162
163 wined3d_context_tls_idx = TlsAlloc();
164 if (wined3d_context_tls_idx == TLS_OUT_OF_INDEXES)
165 {
166 DWORD err = GetLastError();
167 ERR("Failed to allocate context TLS index, err %#x.\n", err);
168 return FALSE;
169 }
170 context_set_tls_idx(wined3d_context_tls_idx);
171
172 /* We need our own window class for a fake window which we use to retrieve GL capabilities */
173 /* We might need CS_OWNDC in the future if we notice strange things on Windows.
174 * Various articles/posts about OpenGL problems on Windows recommend this. */
175 wc.style = CS_HREDRAW | CS_VREDRAW;
176 wc.lpfnWndProc = DefWindowProcA;
177 wc.cbClsExtra = 0;
178 wc.cbWndExtra = 0;
179 wc.hInstance = hInstDLL;
180 wc.hIcon = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
181 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
182 wc.hbrBackground = NULL;
183 wc.lpszMenuName = NULL;
184 wc.lpszClassName = WINED3D_OPENGL_WINDOW_CLASS_NAME;
185
186 if (!RegisterClassA(&wc))
187 {
188 ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
189 if (!TlsFree(wined3d_context_tls_idx))
190 {
191 DWORD err = GetLastError();
192 ERR("Failed to free context TLS index, err %#x.\n", err);
193 }
194 return FALSE;
195 }
196
197 DisableThreadLibraryCalls(hInstDLL);
198
199 mod = GetModuleHandleA( "winex11.drv" );
200 if (mod)
201 {
202 wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
203 wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
204 }
205 else /* We are most likely on Windows */
206 {
207 wine_tsx11_lock_ptr = wined3d_do_nothing;
208 wine_tsx11_unlock_ptr = wined3d_do_nothing;
209 }
210 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
211 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
212
213 len = GetModuleFileNameA( 0, buffer, MAX_PATH );
214 if (len && len < MAX_PATH)
215 {
216 HKEY tmpkey;
217 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
218 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
219 {
220 char *p, *appname = buffer;
221 if ((p = strrchr( appname, '/' ))) appname = p + 1;
222 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
223 strcat( appname, "\\Direct3D" );
224 TRACE("appname = [%s]\n", appname);
225 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
226 RegCloseKey( tmpkey );
227 }
228 }
229
230 if ( 0 != hkey || 0 != appkey )
231 {
232 if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
233 {
234 if (!strcmp(buffer,"none"))
235 {
236 TRACE("Disable vertex shaders\n");
237 wined3d_settings.vs_mode = VS_NONE;
238 }
239 }
240 if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
241 {
242 if (!strcmp(buffer,"enabled"))
243 {
244 TRACE("Allow pixel shaders\n");
245 wined3d_settings.ps_mode = PS_HW;
246 }
247 if (!strcmp(buffer,"disabled"))
248 {
249 TRACE("Disable pixel shaders\n");
250 wined3d_settings.ps_mode = PS_NONE;
251 }
252 }
253 if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
254 {
255 if (!strcmp(buffer,"disabled"))
256 {
257 TRACE("Use of GL Shading Language disabled\n");
258 wined3d_settings.glslRequested = FALSE;
259 }
260 }
261 if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
262 {
263 if (!strcmp(buffer,"backbuffer"))
264 {
265 TRACE("Using the backbuffer for offscreen rendering\n");
266 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
267 }
268 else if (!strcmp(buffer,"fbo"))
269 {
270 TRACE("Using FBOs for offscreen rendering\n");
271 wined3d_settings.offscreen_rendering_mode = ORM_FBO;
272 }
273 }
274 if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
275 {
276 if (!strcmp(buffer,"disabled"))
277 {
278 TRACE("Disabling render target locking\n");
279 wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
280 }
281 else if (!strcmp(buffer,"readdraw"))
282 {
283 TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
284 wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
285 }
286 else if (!strcmp(buffer,"readtex"))
287 {
288 TRACE("Using glReadPixels for render target reading and textures for writing\n");
289 wined3d_settings.rendertargetlock_mode = RTL_READTEX;
290 }
291 }
292 if ( !get_config_key_dword( hkey, appkey, "VideoPciDeviceID", &tmpvalue) )
293 {
294 int pci_device_id = tmpvalue;
295
296 /* A pci device id is 16-bit */
297 if(pci_device_id > 0xffff)
298 {
299 ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
300 }
301 else
302 {
303 TRACE("Using PCI Device ID %04x\n", pci_device_id);
304 wined3d_settings.pci_device_id = pci_device_id;
305 }
306 }
307 if ( !get_config_key_dword( hkey, appkey, "VideoPciVendorID", &tmpvalue) )
308 {
309 int pci_vendor_id = tmpvalue;
310
311 /* A pci device id is 16-bit */
312 if(pci_vendor_id > 0xffff)
313 {
314 ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
315 }
316 else
317 {
318 TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
319 wined3d_settings.pci_vendor_id = pci_vendor_id;
320 }
321 }
322 if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
323 {
324 int TmpVideoMemorySize = atoi(buffer);
325 if(TmpVideoMemorySize > 0)
326 {
327 wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
328 TRACE("Use %iMB = %d byte for emulated_textureram\n",
329 TmpVideoMemorySize,
330 wined3d_settings.emulated_textureram);
331 }
332 else
333 ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
334 }
335 if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
336 {
337 size_t len = strlen(buffer) + 1;
338
339 wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, len);
340 if (!wined3d_settings.logo) ERR("Failed to allocate logo path memory.\n");
341 else memcpy(wined3d_settings.logo, buffer, len);
342 }
343 if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
344 {
345 if (!strcmp(buffer,"enabled"))
346 {
347 TRACE("Allow multisampling\n");
348 wined3d_settings.allow_multisampling = TRUE;
349 }
350 }
351 if (!get_config_key(hkey, appkey, "StrictDrawOrdering", buffer, size)
352 && !strcmp(buffer,"enabled"))
353 {
354 TRACE("Enforcing strict draw ordering.\n");
355 wined3d_settings.strict_draw_ordering = TRUE;
356 }
357 }
358 if (wined3d_settings.vs_mode == VS_HW)
359 TRACE("Allow HW vertex shaders\n");
360 if (wined3d_settings.ps_mode == PS_NONE)
361 TRACE("Disable pixel shaders\n");
362 if (wined3d_settings.glslRequested)
363 TRACE("If supported by your system, GL Shading Language will be used\n");
364
365 if (appkey) RegCloseKey( appkey );
366 if (hkey) RegCloseKey( hkey );
367
368 return TRUE;
369}
370
371static BOOL wined3d_dll_destroy(HINSTANCE hInstDLL)
372{
373 DWORD wined3d_context_tls_idx = context_get_tls_idx();
374 unsigned int i;
375
376 if (!TlsFree(wined3d_context_tls_idx))
377 {
378 DWORD err = GetLastError();
379 ERR("Failed to free context TLS index, err %#x.\n", err);
380 }
381
382 for (i = 0; i < wndproc_table.count; ++i)
383 {
384 struct wined3d_wndproc *entry = &wndproc_table.entries[i];
385 SetWindowLongPtrW(entry->window, GWLP_WNDPROC, (LONG_PTR)entry->proc);
386 }
387 HeapFree(GetProcessHeap(), 0, wndproc_table.entries);
388
389 HeapFree(GetProcessHeap(), 0, wined3d_settings.logo);
390 UnregisterClassA(WINED3D_OPENGL_WINDOW_CLASS_NAME, hInstDLL);
391
392 return TRUE;
393}
394
395void WINAPI wined3d_mutex_lock(void)
396{
397 EnterCriticalSection(&wined3d_cs);
398}
399
400void WINAPI wined3d_mutex_unlock(void)
401{
402 LeaveCriticalSection(&wined3d_cs);
403}
404
405static struct wined3d_wndproc *wined3d_find_wndproc(HWND window)
406{
407 unsigned int i;
408
409 for (i = 0; i < wndproc_table.count; ++i)
410 {
411 if (wndproc_table.entries[i].window == window)
412 {
413 return &wndproc_table.entries[i];
414 }
415 }
416
417 return NULL;
418}
419
420static LRESULT CALLBACK wined3d_wndproc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
421{
422 struct wined3d_wndproc *entry;
423 IWineD3DDeviceImpl *device;
424 WNDPROC proc;
425
426 wined3d_mutex_lock();
427 entry = wined3d_find_wndproc(window);
428
429 if (!entry)
430 {
431 wined3d_mutex_unlock();
432 ERR("Window %p is not registered with wined3d.\n", window);
433 return DefWindowProcW(window, message, wparam, lparam);
434 }
435
436 device = entry->device;
437 proc = entry->proc;
438 wined3d_mutex_unlock();
439
440 return device_process_message(device, window, message, wparam, lparam, proc);
441}
442
443BOOL wined3d_register_window(HWND window, IWineD3DDeviceImpl *device)
444{
445 struct wined3d_wndproc *entry;
446
447 wined3d_mutex_lock();
448
449 if (wndproc_table.size == wndproc_table.count)
450 {
451 unsigned int new_size = max(1, wndproc_table.size * 2);
452 struct wined3d_wndproc *new_entries;
453
454 if (!wndproc_table.entries) new_entries = HeapAlloc(GetProcessHeap(), 0, new_size * sizeof(*new_entries));
455 else new_entries = HeapReAlloc(GetProcessHeap(), 0, wndproc_table.entries, new_size * sizeof(*new_entries));
456
457 if (!new_entries)
458 {
459 wined3d_mutex_unlock();
460 ERR("Failed to grow table.\n");
461 return FALSE;
462 }
463
464 wndproc_table.entries = new_entries;
465 wndproc_table.size = new_size;
466 }
467
468 entry = &wndproc_table.entries[wndproc_table.count++];
469 entry->window = window;
470 entry->proc = (WNDPROC)SetWindowLongPtrW(window, GWLP_WNDPROC, (LONG_PTR)wined3d_wndproc);
471 entry->device = device;
472
473 wined3d_mutex_unlock();
474
475 return TRUE;
476}
477
478void wined3d_unregister_window(HWND window)
479{
480 unsigned int i;
481
482 wined3d_mutex_lock();
483 for (i = 0; i < wndproc_table.count; ++i)
484 {
485 if (wndproc_table.entries[i].window == window)
486 {
487 struct wined3d_wndproc *entry = &wndproc_table.entries[i];
488 struct wined3d_wndproc *last = &wndproc_table.entries[--wndproc_table.count];
489
490 if (GetWindowLongPtrW(window, GWLP_WNDPROC) == (LONG_PTR)wined3d_wndproc)
491 SetWindowLongPtrW(window, GWLP_WNDPROC, (LONG_PTR)entry->proc);
492 if (entry != last) *entry = *last;
493 wined3d_mutex_unlock();
494
495 return;
496 }
497 }
498 wined3d_mutex_unlock();
499
500 ERR("Window %p is not registered with wined3d.\n", window);
501}
502
503/* At process attach */
504BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
505{
506 TRACE("WineD3D DLLMain Reason=%u\n", fdwReason);
507
508 switch (fdwReason)
509 {
510 case DLL_PROCESS_ATTACH:
511 return wined3d_dll_init(hInstDLL);
512
513 case DLL_PROCESS_DETACH:
514 return wined3d_dll_destroy(hInstDLL);
515
516 case DLL_THREAD_DETACH:
517 {
518 if (!context_set_current(NULL))
519 {
520 ERR("Failed to clear current context.\n");
521 }
522 return TRUE;
523 }
524
525 default:
526 return TRUE;
527 }
528}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette