Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Commit 4faa43e

Browse files
committed
Update Windows to sync with Mac changes.
1 parent bfc5cc8 commit 4faa43e

File tree

5 files changed

+35
-57
lines changed

5 files changed

+35
-57
lines changed

latency-benchmark.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
}],
5252
['OS=="win"', {
5353
'sources': [
54-
'src/getopt.c',
54+
'src/win/getopt.c',
5555
'src/win/main.cpp',
5656
'src/win/screenscraper.cpp',
5757
'src/win/stdafx.h',

src/clioptions.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void parse_commandline(int argc, const char **argv, clioptions *options) {
2424
int c;
2525

2626
//TODO: use getopt_long for better looking cli args
27-
while ((c = getopt(argc, (char **)argv, "ab:d:r:e:p:")) != -1) {
27+
while ((c = getopt(argc, (char **)argv, "ab:d:r:e:p:h:")) != -1) {
2828
switch(c) {
2929
case 'a':
3030
options->automated = true;
@@ -41,6 +41,9 @@ void parse_commandline(int argc, const char **argv, clioptions *options) {
4141
case 'p':
4242
options->magic_pattern = optarg;
4343
break;
44+
case 'h':
45+
options->parent_handle = optarg;
46+
break;
4447
case ':':
4548
fprintf(stderr, "Option -%c requires an operand\n", optopt);
4649
print_usage_and_exit();
@@ -55,7 +58,7 @@ void parse_commandline(int argc, const char **argv, clioptions *options) {
5558
if (options->magic_pattern) {
5659
if (options->automated || options->browser || options->results_url ||
5760
options->browser_args) {
58-
fprintf(stderr, "-p is incompatible with all other options.\n");
61+
fprintf(stderr, "-p is incompatible with all other options except -h.\n");
5962
print_usage_and_exit();
6063
}
6164
}

src/clioptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ typedef struct {
1111
char *magic_pattern; // When launching a native reference test window, this
1212
// contains the magic pattern to draw, encoded in
1313
// hexadecimal.
14+
char *parent_handle; // On Windows, this option is passed to child processes
15+
// holding the HANDLE value of their parent.
1416
} clioptions;
1517

1618
void parse_commandline(int argc, const char **argv, clioptions *options);

src/win/main.cpp

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -178,61 +178,34 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
178178
// Prevent automatic DPI scaling.
179179
SetProcessDPIAware();
180180

181-
clioptions *opts = parse_commandline(__argc, (const char **)__argv);
182-
if (opts == NULL) {
183-
return 1;
184-
}
185-
186-
int cliopts = 1;
187-
if (opts->automated)
188-
cliopts++;
189-
190-
if (opts->browser == NULL) {
191-
opts->browser = "";
192-
} else {
193-
cliopts += 2;
194-
}
195-
196-
if (opts->results == NULL) {
197-
opts->results = "";
198-
} else {
199-
cliopts += 2;
200-
}
201-
202-
if (opts->browser_args == NULL) {
203-
opts->browser_args = "";
204-
} else {
205-
cliopts += 2;
206-
}
207-
208-
if (__argc == cliopts) {
209-
debug_log("running server");
210-
HDC desktop = GetDC(NULL);
211-
assert(desktop);
212-
if (GetDeviceCaps(desktop, LOGPIXELSX) != 96) {
213-
MessageBox(NULL, "Unfortunately, due to browser bugs you must set the Windows DPI scaling factor to \"100%\" or \"Smaller\" (96 DPI) for this test to work. Please change it and reboot.",
214-
"Unsupported DPI", MB_ICONERROR | MB_OK);
215-
WinExec("DpiScaling.exe", SW_NORMAL);
181+
clioptions opts;
182+
parse_commandline(__argc, (const char **)__argv, &opts);
183+
184+
if (opts.magic_pattern) {
185+
assert(opts.parent_handle);
186+
debug_log("opening native reference window");
187+
// The -p argument is the magic pattern to draw on the window, encoded as hex.
188+
memset(pattern, 0, sizeof(pattern));
189+
if (!parse_hex_magic_pattern(opts.magic_pattern, pattern)) {
190+
debug_log("Failed to parse pattern");
216191
return 1;
217192
}
218-
ReleaseDC(NULL, desktop);
219-
run_server(opts);
220-
}
221-
free(opts);
222-
223-
debug_log("opening native reference window");
224-
if (__argc != (cliopts+2)) {
225-
debug_log("Unrecognized number of arguments: %d", __argc);
226-
return 1;
227-
}
228-
// The first argument is the magic pattern to draw on the window, encoded as hex.
229-
memset(pattern, 0, sizeof(pattern));
230-
if (!parse_hex_magic_pattern(__argv[cliopts], pattern)) {
231-
debug_log("Failed to parse pattern");
193+
// The -h argument is the HANDLE of the parent process, encoded as hex.
194+
HANDLE parent_process = (HANDLE)_strtoui64(opts.parent_handle, NULL, 16);
195+
message_loop(parent_process);
196+
return 0;
197+
}
198+
199+
debug_log("running server");
200+
HDC desktop = GetDC(NULL);
201+
assert(desktop);
202+
if (GetDeviceCaps(desktop, LOGPIXELSX) != 96) {
203+
MessageBox(NULL, "Unfortunately, due to browser bugs you must set the Windows DPI scaling factor to \"100%\" or \"Smaller\" (96 DPI) for this test to work. Please change it and reboot.",
204+
"Unsupported DPI", MB_ICONERROR | MB_OK);
205+
WinExec("DpiScaling.exe", SW_NORMAL);
232206
return 1;
233207
}
234-
// The second argument is the handle of the parent process.
235-
HANDLE parent_process = (HANDLE)_strtoui64(__argv[cliopts+1], NULL, 16);
236-
message_loop(parent_process);
208+
ReleaseDC(NULL, desktop);
209+
run_server(&opts);
237210
return 0;
238211
}

src/win/screenscraper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ bool open_native_reference_window(uint8_t *test_pattern_for_window) {
419419
// reference window process. If that's too painful, you can configure
420420
// Visual Studio to pass arguments on startup to debug the native reference
421421
// window code in isolation. Here are some sample arguments that will work:
422-
// 2923BEE16CD6529049F1BBE9 0
422+
// -p 2923BEE16CD6529049F1BBE9 -h 0
423423

424424
if (window_process_handle != NULL) {
425425
debug_log("native window already open");
@@ -439,7 +439,7 @@ bool open_native_reference_window(uint8_t *test_pattern_for_window) {
439439
debug_log("DuplicateHandle failed");
440440
return false;
441441
}
442-
sprintf_s(command_line, sizeof(command_line), "%s %s %X", GetCommandLine(),
442+
sprintf_s(command_line, sizeof(command_line), "%s -p %s -h %X", GetCommandLine(),
443443
hex_pattern, current_process_handle);
444444
if (!CreateProcess(NULL, command_line, NULL, NULL, TRUE, 0, NULL, NULL,
445445
&startup_info, &process_info)) {

0 commit comments

Comments
 (0)