1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | // main.cpp: DLL entry point. |
16 | |
17 | #if defined(_WIN32) |
18 | #include "resource.h" |
19 | #include <windows.h> |
20 | |
21 | #ifdef DEBUGGER_WAIT_DIALOG |
22 | static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
23 | { |
24 | RECT rect; |
25 | |
26 | switch(uMsg) |
27 | { |
28 | case WM_INITDIALOG: |
29 | GetWindowRect(GetDesktopWindow(), &rect); |
30 | SetWindowPos(hwnd, HWND_TOP, rect.right / 2, rect.bottom / 2, 0, 0, SWP_NOSIZE); |
31 | SetTimer(hwnd, 1, 100, NULL); |
32 | return TRUE; |
33 | case WM_COMMAND: |
34 | if(LOWORD(wParam) == IDCANCEL) |
35 | { |
36 | EndDialog(hwnd, 0); |
37 | } |
38 | break; |
39 | case WM_TIMER: |
40 | if(IsDebuggerPresent()) |
41 | { |
42 | EndDialog(hwnd, 0); |
43 | } |
44 | } |
45 | |
46 | return FALSE; |
47 | } |
48 | |
49 | static void WaitForDebugger(HINSTANCE instance) |
50 | { |
51 | if(!IsDebuggerPresent()) |
52 | { |
53 | HRSRC dialog = FindResource(instance, MAKEINTRESOURCE(IDD_DIALOG1), RT_DIALOG); |
54 | DLGTEMPLATE *dialogTemplate = (DLGTEMPLATE*)LoadResource(instance, dialog); |
55 | DialogBoxIndirect(instance, dialogTemplate, NULL, DebuggerWaitDialogProc); |
56 | } |
57 | } |
58 | #endif |
59 | |
60 | extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) |
61 | { |
62 | switch(reason) |
63 | { |
64 | case DLL_PROCESS_ATTACH: |
65 | #ifdef DEBUGGER_WAIT_DIALOG |
66 | { |
67 | char disable_debugger_wait_dialog[] = "0" ; |
68 | GetEnvironmentVariable("SWIFTSHADER_DISABLE_DEBUGGER_WAIT_DIALOG" , disable_debugger_wait_dialog, sizeof(disable_debugger_wait_dialog)); |
69 | |
70 | if(disable_debugger_wait_dialog[0] != '1') |
71 | { |
72 | WaitForDebugger(instance); |
73 | } |
74 | } |
75 | #endif |
76 | break; |
77 | case DLL_THREAD_ATTACH: |
78 | case DLL_THREAD_DETACH: |
79 | case DLL_PROCESS_DETACH: |
80 | default: |
81 | break; |
82 | } |
83 | |
84 | return TRUE; |
85 | } |
86 | #endif |
87 | |