ReactOS 0.4.17-dev-972-gd004b2c
wined3d_main.c
Go to the documentation of this file.
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#define VKD3D_NO_VULKAN_H
26#define VKD3D_NO_WIN32_TYPES
27#include "initguid.h"
28#include "wined3d_private.h"
29#include "wined3d_gl.h"
30#include "d3d12.h"
31#define VK_NO_PROTOTYPES
32#include "wine/vulkan.h"
33#include <vkd3d.h>
34
38
40{
48};
49
51{
55};
56
58{
59 HHOOK hook;
61 unsigned int count;
62};
63
65{
68};
69
71{
75
79};
80
83
86{
87 0, 0, &wined3d_cs,
90 0, 0, {(DWORD_PTR)(__FILE__ ": wined3d_cs")}
91};
92static CRITICAL_SECTION wined3d_cs = {&wined3d_cs_debug, -1, 0, 0, 0, 0};
93
96{
97 0, 0, &wined3d_wndproc_cs,
100 0, 0, {(DWORD_PTR)(__FILE__ ": wined3d_wndproc_cs")}
101};
103
106{
107 0, 0, &wined3d_command_cs,
110 0, 0, {(DWORD_PTR)(__FILE__ ": wined3d_command_cs")}
111};
113
114/* When updating default value here, make sure to update winecfg as well,
115 * where appropriate. */
117{
119 .max_gl_version = MAKEDWORD_VERSION(4, 4),
120 .pci_vendor_id = PCI_VENDOR_NONE,
121 .pci_device_id = PCI_DEVICE_NONE,
122 .multisample_textures = TRUE,
123 .sample_count = ~0u,
124 .max_sm_vs = UINT_MAX,
125 .max_sm_ps = UINT_MAX,
126 .max_sm_ds = UINT_MAX,
127 .max_sm_hs = UINT_MAX,
128 .max_sm_gs = UINT_MAX,
129 .max_sm_cs = UINT_MAX,
130 .renderer = WINED3D_RENDERER_AUTO,
131 .shader_backend = WINED3D_SHADER_BACKEND_AUTO,
132};
133
135{
138
140}
141
143{
144 struct wined3d *object;
145 HRESULT hr;
146
147 if (!(object = calloc(1, FIELD_OFFSET(struct wined3d, adapters[1]))))
148 {
149 ERR("Failed to allocate wined3d object memory.\n");
150 return NULL;
151 }
152
155
156 if (FAILED(hr = wined3d_init(object, flags)))
157 {
158 WARN("Failed to initialize wined3d object, hr %#lx.\n", hr);
159 free(object);
160 return NULL;
161 }
162
163 TRACE("Created wined3d object %p.\n", object);
164
165 return object;
166}
167
168static bool is_option_separator(char c)
169{
170 return c == ',' || c == ';' || c == '\0';
171}
172
173static const char *config_list_get_value(const char *string, const char *key, size_t *len)
174{
175 const char *p, *end;
176 char prev_char;
177
178 p = string;
179 while (p)
180 {
181 if ((p = strstr(p, key)))
182 {
183 prev_char = p > string ? p[-1] : 0;
184 p += strlen(key);
185
186 if (is_option_separator(prev_char) && *p == '=')
187 {
188 if ((end = strpbrk(p + 1, ",;")))
189 *len = end - (p + 1);
190 else
191 *len = strlen(p + 1);
192 return p + 1;
193 }
194 }
195 }
196
197 return NULL;
198}
199
200static DWORD get_config_key(HKEY defkey, HKEY appkey, const char *env, const char *name, char *buffer, DWORD size)
201{
202 const char *env_value;
203 size_t env_len;
204
205 if ((env_value = config_list_get_value(env, name, &env_len)) && env_len < size)
206 {
207 memcpy(buffer, env_value, env_len);
208 buffer[env_len] = 0;
209 return 0;
210 }
211 if (appkey && !RegQueryValueExA(appkey, name, 0, NULL, (BYTE *)buffer, &size)) return 0;
212 if (defkey && !RegQueryValueExA(defkey, name, 0, NULL, (BYTE *)buffer, &size)) return 0;
214}
215
216static DWORD get_config_key_dword(HKEY defkey, HKEY appkey, const char *env, const char *name, unsigned int *value)
217{
219 const char *env_value;
220 size_t env_len;
221 char *end;
222
223 if ((env_value = config_list_get_value(env, name, &env_len)))
224 {
225 *value = strtoul(env_value, &end, 0);
226 if (end != env_value)
227 return 0;
228 }
229 size = sizeof(data);
230 if (appkey && !RegQueryValueExA(appkey, name, 0, &type, (BYTE *)&data, &size) && type == REG_DWORD) goto success;
231 size = sizeof(data);
232 if (defkey && !RegQueryValueExA(defkey, name, 0, &type, (BYTE *)&data, &size) && type == REG_DWORD) goto success;
233
235
236success:
237 *value = data;
238 return 0;
239}
240
241BOOL wined3d_get_app_name(char *app_name, unsigned int app_name_size)
242{
243 char buffer[MAX_PATH];
244 unsigned int len;
245 char *p, *name;
246
248 if (!(len && len < MAX_PATH))
249 return FALSE;
250
251 name = buffer;
252 if ((p = strrchr(name, '/' )))
253 name = p + 1;
254 if ((p = strrchr(name, '\\')))
255 name = p + 1;
256
257 len = strlen(name) + 1;
258 if (app_name_size < len)
259 return FALSE;
260
262 return TRUE;
263}
264
265static void vkd3d_log_callback(const char *fmt, va_list args)
266{
267 char buffer[1024];
268
269 vsnprintf(buffer, sizeof(buffer), fmt, args);
271}
272
274{
276 char buffer[MAX_PATH+10];
277 DWORD size = sizeof(buffer);
278 const char *env;
279 HKEY hkey = 0;
280 HKEY appkey = 0;
281 unsigned int tmpvalue;
282 WNDCLASSA wc;
283
286 {
287 unsigned int err = GetLastError();
288 ERR("Failed to allocate context TLS index, err %#x.\n", err);
289 return FALSE;
290 }
292
293 /* We need our own window class for a fake window which we use to retrieve GL capabilities */
294 /* We might need CS_OWNDC in the future if we notice strange things on Windows.
295 * Various articles/posts about OpenGL problems on Windows recommend this. */
298 wc.cbClsExtra = 0;
299 wc.cbWndExtra = 0;
300 wc.hInstance = hInstDLL;
301 wc.hIcon = LoadIconA(NULL, (const char *)IDI_WINLOGO);
302 wc.hCursor = LoadCursorA(NULL, (const char *)IDC_ARROW);
303 wc.hbrBackground = NULL;
304 wc.lpszMenuName = NULL;
306
307 if (!RegisterClassA(&wc))
308 {
309 ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
311 {
312 unsigned int err = GetLastError();
313 ERR("Failed to free context TLS index, err %#x.\n", err);
314 }
315 return FALSE;
316 }
317
319
320 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
321 if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
322
324 {
325 HKEY tmpkey;
326 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
327 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey))
328 {
329 strcat(buffer, "\\Direct3D");
330 TRACE("Application name %s.\n", buffer);
331 if (RegOpenKeyA(tmpkey, buffer, &appkey)) appkey = 0;
332 RegCloseKey(tmpkey);
333 }
334 }
335
336 /* Allow modifying settings using the WINE_D3D_CONFIG environment variable,
337 * which takes precedence over registry keys. An example is as follows:
338 *
339 * WINE_D3D_CONFIG=csmt=0x1,shader_backend=glsl
340 */
341 env = getenv("WINE_D3D_CONFIG");
342
343 if (hkey || appkey || env)
344 {
345 if (!get_config_key_dword(hkey, appkey, env, "csmt", &wined3d_settings.cs_multithreaded))
346 ERR_(winediag)("Setting multithreaded command stream to %#x.\n", wined3d_settings.cs_multithreaded);
347 if (!get_config_key_dword(hkey, appkey, env, "MaxVersionGL", &tmpvalue))
348 {
349 ERR_(winediag)("Setting maximum allowed wined3d GL version to %u.%u.\n",
350 tmpvalue >> 16, tmpvalue & 0xffff);
352 }
353 if (!get_config_key(hkey, appkey, env, "shader_backend", buffer, size))
354 {
355 if (!stricmp(buffer, "glsl-vkd3d"))
356 {
357 ERR_(winediag)("Using the vkd3d-shader GLSL shader backend.\n");
359 }
360 if (!stricmp(buffer, "glsl"))
361 {
362 ERR_(winediag)("Using the GLSL shader backend.\n");
364 }
365 }
366 if (!get_config_key_dword(hkey, appkey, env, "VideoPciDeviceID", &tmpvalue))
367 {
368 int pci_device_id = tmpvalue;
369
370 /* A pci device id is 16-bit */
371 if(pci_device_id > 0xffff)
372 {
373 ERR("Invalid value for VideoPciDeviceID. The value should be smaller or equal to 65535 or 0xffff\n");
374 }
375 else
376 {
377 TRACE("Using PCI Device ID %04x\n", pci_device_id);
378 wined3d_settings.pci_device_id = pci_device_id;
379 }
380 }
381 if (!get_config_key_dword(hkey, appkey, env, "VideoPciVendorID", &tmpvalue))
382 {
383 int pci_vendor_id = tmpvalue;
384
385 /* A pci device id is 16-bit */
386 if(pci_vendor_id > 0xffff)
387 {
388 ERR("Invalid value for VideoPciVendorID. The value should be smaller or equal to 65535 or 0xffff\n");
389 }
390 else
391 {
392 TRACE("Using PCI Vendor ID %04x\n", pci_vendor_id);
393 wined3d_settings.pci_vendor_id = pci_vendor_id;
394 }
395 }
396 if (!get_config_key(hkey, appkey, env, "VideoMemorySize", buffer, size))
397 {
398 int TmpVideoMemorySize = atoi(buffer);
399 if(TmpVideoMemorySize > 0)
400 {
401 wined3d_settings.emulated_textureram = (UINT64)TmpVideoMemorySize *1024*1024;
402 TRACE("Use %iMiB = 0x%s bytes for emulated_textureram\n",
403 TmpVideoMemorySize,
405 }
406 else
407 ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
408 }
409 if (!get_config_key(hkey, appkey, env, "WineLogo", buffer, size))
410 {
411 size_t len = strlen(buffer) + 1;
412
414 ERR("Failed to allocate logo path memory.\n");
415 else
417 }
418 if (!get_config_key_dword(hkey, appkey, env, "MultisampleTextures", &wined3d_settings.multisample_textures))
419 ERR_(winediag)("Setting multisample textures to %#x.\n", wined3d_settings.multisample_textures);
420 if (!get_config_key_dword(hkey, appkey, env, "SampleCount", &wined3d_settings.sample_count))
421 ERR_(winediag)("Forcing sample count to %u. This may not be compatible with all applications.\n",
423 if (!get_config_key(hkey, appkey, env, "CheckFloatConstants", buffer, size)
424 && !strcmp(buffer, "enabled"))
425 {
426 TRACE("Checking relative addressing indices in float constants.\n");
428 }
429 if (!get_config_key_dword(hkey, appkey, env, "strict_shader_math", &wined3d_settings.strict_shader_math))
430 ERR_(winediag)("Setting strict shader math to %#x.\n", wined3d_settings.strict_shader_math);
431 if (!get_config_key_dword(hkey, appkey, env, "MaxShaderModelVS", &wined3d_settings.max_sm_vs))
432 TRACE("Limiting VS shader model to %u.\n", wined3d_settings.max_sm_vs);
433 if (!get_config_key_dword(hkey, appkey, env, "MaxShaderModelHS", &wined3d_settings.max_sm_hs))
434 TRACE("Limiting HS shader model to %u.\n", wined3d_settings.max_sm_hs);
435 if (!get_config_key_dword(hkey, appkey, env, "MaxShaderModelDS", &wined3d_settings.max_sm_ds))
436 TRACE("Limiting DS shader model to %u.\n", wined3d_settings.max_sm_ds);
437 if (!get_config_key_dword(hkey, appkey, env, "MaxShaderModelGS", &wined3d_settings.max_sm_gs))
438 TRACE("Limiting GS shader model to %u.\n", wined3d_settings.max_sm_gs);
439 if (!get_config_key_dword(hkey, appkey, env, "MaxShaderModelPS", &wined3d_settings.max_sm_ps))
440 TRACE("Limiting PS shader model to %u.\n", wined3d_settings.max_sm_ps);
441 if (!get_config_key_dword(hkey, appkey, env, "MaxShaderModelCS", &wined3d_settings.max_sm_cs))
442 TRACE("Limiting CS shader model to %u.\n", wined3d_settings.max_sm_cs);
443 if (!get_config_key(hkey, appkey, env, "renderer", buffer, size))
444 {
445 if (!strcmp(buffer, "vulkan"))
446 {
447 ERR_(winediag)("Using the Vulkan renderer.\n");
449 }
450 else if (!strcmp(buffer, "gl"))
451 {
452 ERR_(winediag)("Using the OpenGL renderer.\n");
454 }
455 else if (!strcmp(buffer, "gdi") || !strcmp(buffer, "no3d"))
456 {
457 ERR_(winediag)("Disabling 3D support.\n");
459 }
460 }
461 if (!get_config_key_dword(hkey, appkey, env, "cb_access_map_w", &tmpvalue) && tmpvalue)
462 {
463 TRACE("Forcing all constant buffers to be write-mappable.\n");
465 }
466 if (!get_config_key_dword(hkey, appkey, env, "ffp_hlsl", &tmpvalue))
467 {
468 ERR_(winediag)("Using the HLSL-based FFP backend.\n");
469 wined3d_settings.ffp_hlsl = tmpvalue;
470 }
471 }
472
473 if (appkey) RegCloseKey( appkey );
474 if (hkey) RegCloseKey( hkey );
475
476 if (!getenv( "VKD3D_DEBUG" ))
477 {
478 if (TRACE_ON(vkd3d)) putenv( "VKD3D_DEBUG=trace" );
479 else if (WARN_ON(vkd3d)) putenv( "VKD3D_DEBUG=warn" );
480 else if (FIXME_ON(vkd3d)) putenv( "VKD3D_DEBUG=fixme" );
481 else if (ERR_ON(vkd3d)) putenv( "VKD3D_DEBUG=err" );
482 else putenv( "VKD3D_DEBUG=none" );
483 }
484 if (!getenv( "VKD3D_SHADER_DEBUG" ))
485 {
486 if (TRACE_ON(vkd3d)) putenv( "VKD3D_SHADER_DEBUG=trace" );
487 else if (WARN_ON(vkd3d)) putenv( "VKD3D_SHADER_DEBUG=warn" );
488 else if (FIXME_ON(vkd3d)) putenv( "VKD3D_SHADER_DEBUG=fixme" );
489 else if (ERR_ON(vkd3d)) putenv( "VKD3D_SHADER_DEBUG=err" );
490 else putenv( "VKD3D_SHADER_DEBUG=none" );
491 }
492
494
495 return TRUE;
496}
497
499{
501 unsigned int i;
502
504 {
505 unsigned int err = GetLastError();
506 ERR("Failed to free context TLS index, err %#x.\n", err);
507 }
508
509 for (i = 0; i < wndproc_table.count; ++i)
510 {
511 /* Trying to unregister these would be futile. These entries can only
512 * exist if either we skipped them in wined3d_unregister_window() due
513 * to the application replacing the wndproc after the entry was
514 * registered, or if the application still has an active wined3d
515 * device. In the latter case the application has bigger problems than
516 * these entries. */
517 WARN("Leftover wndproc table entry %p.\n", &wndproc_table.entries[i]);
518 }
519 free(wndproc_table.entries);
520
522 for (i = 0; i < swapchain_state_table.hook_count; ++i)
523 {
524 WARN("Leftover swapchain state hook %p.\n", &swapchain_state_table.hooks[i]);
526 }
528
531
533
536 return TRUE;
537}
538
540{
542}
543
545{
547}
548
550{
552}
553
555{
557}
558
560 HWND hwnd)
561{
562 unsigned int adapter_idx, output_idx;
563 struct wined3d_adapter *adapter;
565 HMONITOR monitor;
566
567 TRACE("wined3d %p, hwnd %p.\n", wined3d, hwnd);
568
569 monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
570 monitor_info.cbSize = sizeof(monitor_info);
571 if (!GetMonitorInfoW(monitor, (MONITORINFO *)&monitor_info))
572 {
573 ERR("GetMonitorInfoW failed, error %#lx.\n", GetLastError());
574 return NULL;
575 }
576
577 for (adapter_idx = 0; adapter_idx < wined3d->adapter_count; ++adapter_idx)
578 {
579 adapter = wined3d->adapters[adapter_idx];
580 for (output_idx = 0; output_idx < adapter->output_count; ++output_idx)
581 {
582 if (!lstrcmpiW(adapter->outputs[output_idx].device_name, monitor_info.szDevice))
583 return &adapter->outputs[output_idx];
584 }
585 }
586
587 return NULL;
588}
589
591{
592 unsigned int i;
593
594 for (i = 0; i < wndproc_table.count; ++i)
595 {
596 struct wined3d_wndproc *entry = &wndproc_table.entries[i];
597
598 if (entry->window == window && entry->wined3d == wined3d)
599 return entry;
600 }
601
602 return NULL;
603}
604
606{
607 struct wined3d_wndproc *entry;
608 BOOL ret;
609
611
613 {
615 return FALSE;
616 }
617
618 ret = entry->filter;
619 entry->filter = filter;
620
622
623 return ret;
624}
625
627{
628 struct wined3d_wndproc *entry;
629 struct wined3d_device *device;
630 BOOL unicode, filter;
632
634
636 {
638 ERR("Window %p is not registered with wined3d.\n", window);
640 }
641
642 device = entry->device;
643 unicode = entry->unicode;
644 filter = entry->filter;
645 proc = entry->proc;
647
648 if (device)
649 {
650 if (filter && message != WM_DISPLAYCHANGE)
651 {
652 TRACE("Filtering message: window %p, message %#x, wparam %#Ix, lparam %#Ix.\n",
654
655 if (unicode)
658 }
659
661 }
662 if (unicode)
665}
666
668{
669 struct wined3d_swapchain_desc swapchain_desc;
671 struct wined3d_wndproc *entry;
672 struct wined3d_output *output;
673 MSG *msg = (MSG *)lparam;
674 unsigned int i;
675
676 /* Handle Alt+Enter. */
677 if (code == HC_ACTION && msg->message == WM_SYSKEYDOWN
678 && msg->wParam == VK_RETURN && (msg->lParam & (KF_ALTDOWN << 16)))
679 {
681
682 for (i = 0; i < swapchain_state_table.state_count; ++i)
683 {
684 state = swapchain_state_table.states[i].state;
685
686 if (state->device_window != msg->hwnd)
687 continue;
688
689 if ((entry = wined3d_find_wndproc(msg->hwnd, state->wined3d))
692 continue;
693
694 swapchain_desc = state->desc;
695 swapchain_desc.windowed = !swapchain_desc.windowed;
696 if (!(output = wined3d_get_output_from_window(state->wined3d, state->device_window)))
697 {
698 ERR("Failed to get output from window %p.\n", state->device_window);
699 break;
700 }
701 swapchain_desc.output = output;
703
705
706 return 1;
707 }
708
710 }
711
712 return CallNextHookEx(0, code, wparam, lparam);
713}
714
716 struct wined3d_device *device, unsigned int flags)
717{
718 struct wined3d_wndproc *entry;
719
720 TRACE("wined3d %p, window %p, device %p, flags %#x.\n", wined3d, window, device, flags);
721
723
725 {
726 if (!wined3d)
727 WARN("Window %p is already registered with wined3d.\n", window);
728 entry->flags = flags;
730 return TRUE;
731 }
732
733 if (!wined3d_array_reserve((void **)&wndproc_table.entries, &wndproc_table.size,
734 wndproc_table.count + 1, sizeof(*entry)))
735 {
737 ERR("Failed to grow table.\n");
738 return FALSE;
739 }
740
741 entry = &wndproc_table.entries[wndproc_table.count++];
742 entry->window = window;
743 entry->unicode = IsWindowUnicode(window);
744 if (!wined3d)
745 {
746 /* Set a window proc that matches the window. Some applications (e.g.
747 * NoX) replace the window proc after we've set ours, and expect to be
748 * able to call the previous one (ours) directly, without using
749 * CallWindowProc(). */
750 if (entry->unicode)
752 else
754 }
755 else
756 {
757 entry->proc = NULL;
758 }
759 entry->device = device;
760 entry->wined3d = wined3d;
761 entry->flags = flags;
762
764
765 return TRUE;
766}
767
769{
771
772 if (entry->unicode)
773 {
776 return FALSE;
778 }
779 else
780 {
783 return FALSE;
785 }
786
787 return TRUE;
788}
789
791{
792 struct wined3d_wndproc *entry, *last;
793
795
797 {
799 ERR("Window %p is not registered with wined3d.\n", window);
800 return;
801 }
802
803 if (entry->proc && !restore_wndproc(entry))
804 {
805 entry->device = NULL;
806 WARN("Not unregistering window %p, current window proc doesn't match wined3d window proc.\n", window);
808 return;
809 }
810
811 last = &wndproc_table.entries[--wndproc_table.count];
812 if (entry != last) *entry = *last;
813
815}
816
818{
819 struct wined3d_wndproc *entry, *last;
820 unsigned int i = 0;
821
822 TRACE("wined3d %p.\n", wined3d);
823
825
826 while (i < wndproc_table.count)
827 {
828 entry = &wndproc_table.entries[i];
829
830 if (entry->wined3d != wined3d)
831 {
832 ++i;
833 continue;
834 }
835
836 if (entry->proc && !restore_wndproc(entry))
837 {
838 entry->device = NULL;
839 WARN("Not unregistering window %p, current window proc doesn't match wined3d window proc.\n",
840 entry->window);
841 ++i;
842 continue;
843 }
844
845 last = &wndproc_table.entries[--wndproc_table.count];
846 if (entry != last)
847 *entry = *last;
848 else
849 ++i;
850 }
851
853}
854
856{
857 unsigned int i;
858
859 for (i = 0; i < swapchain_state_table.hook_count; ++i)
860 {
861 if (swapchain_state_table.hooks[i].thread_id == thread_id)
862 return &swapchain_state_table.hooks[i];
863 }
864
865 return NULL;
866}
867
869{
872
874
875 if (!wined3d_array_reserve((void **)&swapchain_state_table.states, &swapchain_state_table.states_size,
876 swapchain_state_table.state_count + 1, sizeof(*state_entry)))
877 {
879 return;
880 }
881
884 state_entry->thread_id = GetWindowThreadProcessId(state->device_window, NULL);
885
886 if ((hook = wined3d_find_hook(state_entry->thread_id)))
887 {
888 ++hook->count;
890 return;
891 }
892
893 if (!wined3d_array_reserve((void **)&swapchain_state_table.hooks, &swapchain_state_table.hooks_size,
894 swapchain_state_table.hook_count + 1, sizeof(*hook)))
895 {
896 --swapchain_state_table.state_count;
898 return;
899 }
900
901 hook = &swapchain_state_table.hooks[swapchain_state_table.hook_count++];
902 hook->thread_id = state_entry->thread_id;
904 hook->count = 1;
905
907}
908
910{
911 struct wined3d_registered_swapchain_state *state_entry, *last_state_entry;
912 struct wined3d_window_hook *hook, *last_hook;
913 unsigned int i;
914
916
917 for (i = 0; i < swapchain_state_table.state_count; ++i)
918 {
920
921 if (state_entry->state != state)
922 continue;
923
924 if ((hook = wined3d_find_hook(state_entry->thread_id)) && !--hook->count)
925 {
927 last_hook = &swapchain_state_table.hooks[--swapchain_state_table.hook_count];
928 if (hook != last_hook)
929 *hook = *last_hook;
930 }
931
932 last_state_entry = &swapchain_state_table.states[--swapchain_state_table.state_count];
933 if (state_entry != last_state_entry)
934 *state_entry = *last_state_entry;
935
936 break;
937 }
938
940}
941
943{
945}
946
947/* At process attach */
949{
950 switch (reason)
951 {
953 return wined3d_dll_init(inst);
954
956 if (!reserved)
957 return wined3d_dll_destroy(inst);
958 break;
959
962 {
963 ERR("Failed to clear current context.\n");
964 }
965 return TRUE;
966 }
967 return TRUE;
968}
@ lparam
Definition: SystemMenu.c:31
@ hook
Definition: SystemMenu.c:35
@ wparam
Definition: SystemMenu.c:30
COMPILER_DEPENDENT_UINT64 UINT64
Definition: actypes.h:131
#define vsnprintf
Definition: acwin.h:108
static int state
Definition: maze.c:121
#define msg(x)
Definition: auth_time.c:54
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define RegCloseKey(hKey)
Definition: registry.h:49
void context_set_tls_idx(DWORD idx)
Definition: context_gl.c:1561
BOOL wined3d_context_gl_set_current(struct wined3d_context_gl *context_gl)
Definition: context_gl.c:1571
static DWORD wined3d_context_tls_idx
Definition: context_gl.c:37
DWORD context_get_tls_idx(void)
Definition: context_gl.c:1556
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:171
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UINT32 uint32_t
Definition: types.h:75
LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode, UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc)
Definition: device.c:5588
BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
Definition: utils.c:6740
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3234
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1971
#define CDECL
Definition: compat.h:29
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define TRACE_ON(x)
Definition: compat.h:75
#define stricmp(_String1, _String2)
Definition: compat.h:24
#define MAX_PATH
Definition: compat.h:34
#define WINE_DECLARE_DEBUG_CHANNEL(x)
Definition: compat.h:45
#define CALLBACK
Definition: compat.h:35
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
BOOL WINAPI TlsFree(IN DWORD Index)
Definition: thread.c:1224
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4171
DWORD WINAPI DECLSPEC_HOTPATCH TlsAlloc(void)
Definition: thread.c:657
char *CDECL getenv(const char *name)
Definition: environ.c:227
#define UINT_MAX
Definition: limits.h:27
_ACRTIMP int __cdecl atoi(const char *)
Definition: string.c:1720
_ACRTIMP __msvcrt_ulong __cdecl strtoul(const char *, char **, int)
Definition: string.c:1864
static int putenv(const char *str)
Definition: stdlib.h:294
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3420
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
_ACRTIMP char *__cdecl strpbrk(const char *, const char *)
Definition: string.c:3530
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3303
char * va_list
Definition: vadefs.h:50
return ret
Definition: mutex.c:147
r reserved
Definition: btrfs.c:3006
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
return adapter
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
GLbitfield flags
Definition: glext.h:7161
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
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
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 * u
Definition: glfuncs.h:240
unsigned int UINT
Definition: sysinfo.c:13
#define FAILED(hr)
Definition: intsafe.h:51
uint32_t entry
Definition: isohybrid.c:63
LONG_PTR LPARAM
Definition: minwindef.h:175
LONG_PTR LRESULT
Definition: minwindef.h:176
UINT_PTR WPARAM
Definition: minwindef.h:174
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define WARN_ON(c)
Definition: module.h:257
char string[160]
Definition: util.h:11
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static const LARGE_INTEGER *static const HANDLE const LARGE_INTEGER *static PSLIST_ENTRY PSLIST_ENTRY last
Definition: sync.c:64
static IHTMLWindow2 * window
Definition: events.c:77
static DWORD thread_id
Definition: protocol.c:164
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
HMONITOR WINAPI MonitorFromWindow(HWND, DWORD)
LPCWSTR app_name
Definition: notevil.c:34
static HANDLE proc()
Definition: pdb.c:32
#define state_entry(pos)
Definition: pnfs_layout.c:39
#define CS_VREDRAW
Definition: winuser.h:666
#define SetWindowLongPtrA
Definition: winuser.h:5511
#define GetWindowLongPtrW
Definition: winuser.h:4983
BOOL WINAPI UnregisterClassA(_In_ LPCSTR, HINSTANCE)
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HHOOK WINAPI SetWindowsHookExW(_In_ int, _In_ HOOKPROC, _In_opt_ HINSTANCE, _In_ DWORD)
#define CS_HREDRAW
Definition: winuser.h:661
#define KF_ALTDOWN
Definition: winuser.h:2485
#define IDC_ARROW
Definition: winuser.h:695
#define HC_ACTION
Definition: winuser.h:48
#define GetWindowLongPtrA
Definition: winuser.h:4982
#define IDI_WINLOGO
Definition: winuser.h:717
BOOL WINAPI IsWindowUnicode(_In_ HWND)
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
#define VK_RETURN
Definition: winuser.h:2237
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)
HICON WINAPI LoadIconA(_In_opt_ HINSTANCE hInstance, _In_ LPCSTR lpIconName)
Definition: cursoricon.c:2429
#define WH_GETMESSAGE
Definition: winuser.h:33
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI GetMonitorInfoW(_In_ HMONITOR, _Inout_ LPMONITORINFO)
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:3014
#define SetWindowLongPtrW
Definition: winuser.h:5512
LRESULT WINAPI CallWindowProcW(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_SYSKEYDOWN
Definition: winuser.h:1747
LRESULT WINAPI CallWindowProcA(_In_ WNDPROC, _In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
Definition: cursoricon.c:2459
#define err(...)
#define calloc
Definition: rosglue.h:14
#define REG_DWORD
Definition: sdbapi.c:615
#define ERR_(ch,...)
Definition: debug.h:156
strcat
Definition: string.h:92
#define FIXME_ON(ch)
Definition: debug.h:418
const char int int __cdecl __wine_dbg_output(const char *str)
Definition: debug.c:273
#define ERR_ON(ch)
Definition: debug.h:423
#define TRACE(s)
Definition: solgame.cpp:4
HBRUSH hbrBackground
Definition: winuser.h:3278
HICON hIcon
Definition: winuser.h:3276
HINSTANCE hInstance
Definition: winuser.h:3275
HCURSOR hCursor
Definition: winuser.h:3277
int cbWndExtra
Definition: winuser.h:3274
UINT style
Definition: winuser.h:3271
LPCSTR lpszMenuName
Definition: winuser.h:3279
LPCSTR lpszClassName
Definition: winuser.h:3280
WNDPROC lpfnWndProc
Definition: winuser.h:3272
int cbClsExtra
Definition: winuser.h:3273
Definition: match.c:390
Definition: inflate.c:139
Definition: devices.h:37
Definition: filter.c:165
Definition: dsound.c:943
Definition: copy.c:22
Definition: tftpd.h:60
Definition: name.c:39
Definition: performance.c:575
IDirectMusicSegmentState * state
Definition: performance.c:577
struct wined3d_swapchain_state * state
Definition: wined3d_main.c:66
unsigned int max_sm_hs
unsigned int max_gl_version
enum wined3d_shader_backend shader_backend
unsigned int max_sm_vs
unsigned int cs_multithreaded
unsigned int multisample_textures
unsigned int max_sm_ps
unsigned int max_sm_cs
unsigned int max_sm_ds
unsigned int strict_shader_math
unsigned int sample_count
unsigned int max_sm_gs
unsigned short pci_vendor_id
enum wined3d_renderer renderer
unsigned short pci_device_id
struct wined3d_output * output
Definition: wined3d.h:1771
struct wined3d_registered_swapchain_state * states
Definition: wined3d_main.c:76
struct wined3d_window_hook * hooks
Definition: wined3d_main.c:72
unsigned int count
Definition: wined3d_main.c:61
struct wined3d_wndproc * entries
Definition: wined3d_main.c:52
struct wined3d * wined3d
Definition: wined3d_main.c:41
uint32_t flags
Definition: wined3d_main.c:47
struct wined3d_device * device
Definition: wined3d_main.c:46
unsigned int adapter_count
struct wined3d_adapter * adapters[1]
#define GWLP_WNDPROC
Definition: treelist.c:66
#define DWORD_PTR
Definition: treelist.c:76
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
ULONG_PTR SIZE_T
Definition: typedefs.h:80
Definition: pdh_main.c:64
VKD3D_API void vkd3d_set_log_callback(PFN_vkd3d_log callback)
Definition: vkd3d_main.c:513
#define success(from, fromstr, to, tostr)
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define TLS_OUT_OF_INDEXES
Definition: winbase.h:529
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WINAPI
Definition: msvc.h:6
HRESULT wined3d_init(struct wined3d *wined3d, uint32_t flags)
Definition: directx.c:3477
HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_state *state, const struct wined3d_swapchain_desc *swapchain_desc, const struct wined3d_display_mode *mode)
Definition: swapchain.c:2344
#define WINED3D_NO3D
Definition: wined3d.h:1323
wined3d_renderer
Definition: wined3d.h:57
@ WINED3D_RENDERER_VULKAN
Definition: wined3d.h:59
@ WINED3D_RENDERER_AUTO
Definition: wined3d.h:58
@ WINED3D_RENDERER_OPENGL
Definition: wined3d.h:60
@ WINED3D_RENDERER_NO3D
Definition: wined3d.h:61
#define WINED3D_REGISTER_WINDOW_NO_WINDOW_CHANGES
Definition: wined3d.h:1592
#define WINED3D_REGISTER_WINDOW_NO_ALT_ENTER
Definition: wined3d.h:1593
static struct wined3d_swapchain_state_table swapchain_state_table
Definition: wined3d_main.c:82
static CRITICAL_SECTION_DEBUG wined3d_cs_debug
Definition: wined3d_main.c:85
static DWORD get_config_key_dword(HKEY defkey, HKEY appkey, const char *env, const char *name, unsigned int *value)
Definition: wined3d_main.c:216
static CRITICAL_SECTION_DEBUG wined3d_command_cs_debug
Definition: wined3d_main.c:105
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
BOOL wined3d_filter_messages(HWND window, BOOL filter)
Definition: wined3d_main.c:605
static void wined3d_swapchain_state_unregister(struct wined3d_swapchain_state *state)
Definition: wined3d_main.c:909
void wined3d_swapchain_state_cleanup(struct wined3d_swapchain_state *state)
Definition: wined3d_main.c:942
static bool is_option_separator(char c)
Definition: wined3d_main.c:168
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539
struct wined3d *CDECL wined3d_create(uint32_t flags)
Definition: wined3d_main.c:142
BOOL wined3d_get_app_name(char *app_name, unsigned int app_name_size)
Definition: wined3d_main.c:241
static void vkd3d_log_callback(const char *fmt, va_list args)
Definition: wined3d_main.c:265
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
Definition: wined3d_main.c:948
BOOL CDECL wined3d_register_window(struct wined3d *wined3d, HWND window, struct wined3d_device *device, unsigned int flags)
Definition: wined3d_main.c:715
static DWORD get_config_key(HKEY defkey, HKEY appkey, const char *env, const char *name, char *buffer, DWORD size)
Definition: wined3d_main.c:200
static CRITICAL_SECTION_DEBUG wined3d_wndproc_cs_debug
Definition: wined3d_main.c:95
CRITICAL_SECTION wined3d_command_cs
Definition: wined3d_main.c:104
void wined3d_swapchain_state_register(struct wined3d_swapchain_state *state)
Definition: wined3d_main.c:868
static struct wined3d_wndproc * wined3d_find_wndproc(HWND window, struct wined3d *wined3d)
Definition: wined3d_main.c:590
static struct wined3d_wndproc_table wndproc_table
Definition: wined3d_main.c:81
static const char * config_list_get_value(const char *string, const char *key, size_t *len)
Definition: wined3d_main.c:173
static BOOL wined3d_dll_destroy(HINSTANCE hInstDLL)
Definition: wined3d_main.c:498
static LRESULT CALLBACK wined3d_hook_proc(int code, WPARAM wparam, LPARAM lparam)
Definition: wined3d_main.c:667
static CRITICAL_SECTION wined3d_wndproc_cs
Definition: wined3d_main.c:94
static void wined3d_wndproc_mutex_lock(void)
Definition: wined3d_main.c:549
void CDECL wined3d_unregister_windows(struct wined3d *wined3d)
Definition: wined3d_main.c:817
static struct wined3d_output * wined3d_get_output_from_window(const struct wined3d *wined3d, HWND hwnd)
Definition: wined3d_main.c:559
static CRITICAL_SECTION wined3d_cs
Definition: wined3d_main.c:84
static BOOL wined3d_dll_init(HINSTANCE hInstDLL)
Definition: wined3d_main.c:273
static void wined3d_wndproc_mutex_unlock(void)
Definition: wined3d_main.c:554
void wined3d_unregister_window(HWND window)
Definition: wined3d_main.c:790
enum wined3d_renderer CDECL wined3d_get_renderer(void)
Definition: wined3d_main.c:134
static struct wined3d_window_hook * wined3d_find_hook(DWORD thread_id)
Definition: wined3d_main.c:855
static BOOL restore_wndproc(struct wined3d_wndproc *entry)
Definition: wined3d_main.c:768
#define WINED3D_OPENGL_WINDOW_CLASS_NAME
#define PCI_VENDOR_NONE
#define MAKEDWORD_VERSION(maj, min)
#define PCI_DEVICE_NONE
#define WINED3D_CSMT_ENABLE
@ WINED3D_SHADER_BACKEND_AUTO
@ WINED3D_SHADER_BACKEND_GLSL
@ WINED3D_SHADER_BACKEND_GLSL_VKD3D
#define HKEY_CURRENT_USER
Definition: winreg.h:11
unsigned char BYTE
Definition: xxhash.c:193