mirrored from git://source.winehq.org/git/wine.git
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
monitor.c
2285 lines (1980 loc) · 101 KB
/
monitor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Unit tests for monitor APIs
*
* Copyright 2005 Huw Davies
* Copyright 2008 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "wine/test.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winreg.h"
#include "wine/heap.h"
#include <stdio.h>
static HMODULE hdll;
static LONG (WINAPI *pGetDisplayConfigBufferSizes)(UINT32,UINT32*,UINT32*);
static LONG (WINAPI *pQueryDisplayConfig)(UINT32,UINT32*,DISPLAYCONFIG_PATH_INFO*,UINT32*,
DISPLAYCONFIG_MODE_INFO*,DISPLAYCONFIG_TOPOLOGY_ID*);
static LONG (WINAPI *pDisplayConfigGetDeviceInfo)(DISPLAYCONFIG_DEVICE_INFO_HEADER*);
static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
static void init_function_pointers(void)
{
hdll = GetModuleHandleA("user32.dll");
#define GET_PROC(func) \
p ## func = (void*)GetProcAddress(hdll, #func); \
if(!p ## func) \
trace("GetProcAddress(%s) failed\n", #func);
GET_PROC(GetDisplayConfigBufferSizes)
GET_PROC(QueryDisplayConfig)
GET_PROC(DisplayConfigGetDeviceInfo)
GET_PROC(SetThreadDpiAwarenessContext)
#undef GET_PROC
}
static void flush_events(void)
{
int diff = 1000;
DWORD time;
MSG msg;
time = GetTickCount() + diff;
while (diff > 0)
{
if (MsgWaitForMultipleObjects(0, NULL, FALSE, 200, QS_ALLINPUT) == WAIT_TIMEOUT)
break;
while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
DispatchMessageA(&msg);
diff = time - GetTickCount();
}
}
static int get_bitmap_stride(int width, int bpp)
{
return ((width * bpp + 15) >> 3) & ~1;
}
static BOOL CALLBACK monitor_enum_proc(HMONITOR hmon, HDC hdc, LPRECT lprc,
LPARAM lparam)
{
MONITORINFOEXA mi;
char *primary = (char *)lparam;
mi.cbSize = sizeof(mi);
ok(GetMonitorInfoA(hmon, (MONITORINFO*)&mi), "GetMonitorInfo failed\n");
if (mi.dwFlags & MONITORINFOF_PRIMARY)
strcpy(primary, mi.szDevice);
return TRUE;
}
static int adapter_count = 0;
static int monitor_count = 0;
static void test_enumdisplaydevices_adapter(int index, const DISPLAY_DEVICEA *device, DWORD flags)
{
char buffer[128];
int number;
int vendor_id;
int device_id;
int subsys_id;
int revision_id;
HDC hdc;
adapter_count++;
/* DeviceName */
ok(sscanf(device->DeviceName, "\\\\.\\DISPLAY%d", &number) == 1, "#%d: wrong DeviceName %s\n", index,
device->DeviceName);
/* DeviceKey */
/* \Device\Video? value in HLKM\HARDWARE\DEVICEMAP\VIDEO are not necessarily in order with adapter index.
* Check format only */
ok(sscanf(device->DeviceKey, "\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Video\\%[^\\]\\%04d", buffer, &number) == 2,
"#%d: wrong DeviceKey %s\n", index, device->DeviceKey);
/* DeviceString */
ok(broken(!*device->DeviceString) || /* XP on Testbot will return an empty string, whereas XP on real machine doesn't. Probably a bug in virtual adapter driver */
*device->DeviceString, "#%d: expect DeviceString not empty\n", index);
/* StateFlags */
if (index == 0)
ok(device->StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE, "#%d: adapter should be primary\n", index);
else
ok(!(device->StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE), "#%d: adapter should not be primary\n", index);
if (device->StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
{
/* Test creating DC */
hdc = CreateDCA(device->DeviceName, NULL, NULL, NULL);
ok(hdc != NULL, "#%d: failed to CreateDC(\"%s\") err=%d\n", index, device->DeviceName, GetLastError());
DeleteDC(hdc);
}
/* DeviceID */
/* DeviceID should equal to the first string of HardwareID value data in PCI GPU instance. You can verify this
* by changing the data and rerun EnumDisplayDevices. But it's difficult to find corresponding PCI device on
* userland. So here we check the expected format instead. */
if (flags & EDD_GET_DEVICE_INTERFACE_NAME)
ok(strlen(device->DeviceID) == 0 || /* vista+ */
sscanf(device->DeviceID, "PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X",
&vendor_id, &device_id, &subsys_id, &revision_id) == 4, /* XP/2003 ignores EDD_GET_DEVICE_INTERFACE_NAME */
"#%d: got %s\n", index, device->DeviceID);
else
{
ok(broken(strlen(device->DeviceID) == 0) || /* XP on Testbot returns an empty string, whereas real machine doesn't */
sscanf(device->DeviceID, "PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X", &vendor_id, &device_id, &subsys_id,
&revision_id) == 4, "#%d: wrong DeviceID %s\n", index, device->DeviceID);
}
}
static void test_enumdisplaydevices_monitor(int adapter_index, int monitor_index, const char *adapter_name,
DISPLAY_DEVICEA *device, DWORD flags)
{
static const char device_key_prefix[] = "\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class"
"\\{4d36e96e-e325-11ce-bfc1-08002be10318}\\";
char monitor_name[32];
char buffer[128];
int number;
monitor_count++;
/* DeviceName */
lstrcpyA(monitor_name, adapter_name);
sprintf(monitor_name + strlen(monitor_name), "\\Monitor%d", monitor_index);
ok(!strcmp(monitor_name, device->DeviceName), "#%d: expect %s, got %s\n", monitor_index, monitor_name, device->DeviceName);
/* DeviceString */
ok(*device->DeviceString, "#%d: expect DeviceString not empty\n", monitor_index);
/* StateFlags */
if (adapter_index == 0 && monitor_index == 0)
ok(device->StateFlags & DISPLAY_DEVICE_ATTACHED, "#%d expect to have a primary monitor attached\n", monitor_index);
else
ok(device->StateFlags <= (DISPLAY_DEVICE_ATTACHED | DISPLAY_DEVICE_ACTIVE), "#%d wrong state %#x\n", monitor_index,
device->StateFlags);
/* DeviceID */
CharLowerA(device->DeviceID);
if (flags & EDD_GET_DEVICE_INTERFACE_NAME)
{ /* HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\[monitor name]\[instance id] GUID_DEVINTERFACE_MONITOR
* ^ ^ ^
* Expect format \\?\DISPLAY#[monitor name]#[instance id]#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7} */
ok(strlen(device->DeviceID) == 0 || /* vista ~ win7 */
sscanf(device->DeviceID, "\\\\?\\display#%[^#]#%[^#]#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}", buffer, buffer) == 2 || /* win8+ */
sscanf(device->DeviceID, "monitor\\%[^\\]\\{4d36e96e-e325-11ce-bfc1-08002be10318}\\%04d", buffer, &number) == 2, /* XP/2003 ignores EDD_GET_DEVICE_INTERFACE_NAME */
"#%d: wrong DeviceID : %s\n", monitor_index, device->DeviceID);
}
else
{
/* Expect HarewareID value data + Driver value data in HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\[monitor name]\{instance} */
/* But we don't know which monitor instance this belongs to, so check format instead */
ok(sscanf(device->DeviceID, "monitor\\%[^\\]\\{4d36e96e-e325-11ce-bfc1-08002be10318}\\%04d", buffer, &number) == 2,
"#%d: wrong DeviceID : %s\n", monitor_index, device->DeviceID);
}
/* DeviceKey */
lstrcpynA(buffer, device->DeviceKey, sizeof(device_key_prefix));
ok(!lstrcmpiA(buffer, device_key_prefix), "#%d: wrong DeviceKey : %s\n", monitor_index, device->DeviceKey);
ok(sscanf(device->DeviceKey + sizeof(device_key_prefix) - 1, "%04d", &number) == 1,
"#%d wrong DeviceKey : %s\n", monitor_index, device->DeviceKey);
}
static void test_enumdisplaydevices(void)
{
static const DWORD flags[] = {0, EDD_GET_DEVICE_INTERFACE_NAME};
DISPLAY_DEVICEA dd;
char primary_device_name[32];
char primary_monitor_device_name[32];
char adapter_name[32];
int number;
int flag_index;
int adapter_index;
int monitor_index;
BOOL ret;
/* Doesn't accept \\.\DISPLAY */
dd.cb = sizeof(dd);
ret = EnumDisplayDevicesA("\\\\.\\DISPLAY", 0, &dd, 0);
ok(!ret, "Expect failure\n");
/* Enumeration */
for (flag_index = 0; flag_index < ARRAY_SIZE(flags); flag_index++)
for (adapter_index = 0; EnumDisplayDevicesA(NULL, adapter_index, &dd, flags[flag_index]); adapter_index++)
{
lstrcpyA(adapter_name, dd.DeviceName);
if (sscanf(adapter_name, "\\\\.\\DISPLAYV%d", &number) == 1)
{
skip("Skipping software devices %s:%s\n", adapter_name, dd.DeviceString);
continue;
}
test_enumdisplaydevices_adapter(adapter_index, &dd, flags[flag_index]);
for (monitor_index = 0; EnumDisplayDevicesA(adapter_name, monitor_index, &dd, flags[flag_index]);
monitor_index++)
test_enumdisplaydevices_monitor(adapter_index, monitor_index, adapter_name, &dd, flags[flag_index]);
}
ok(adapter_count > 0, "Expect at least one adapter found\n");
/* XP on Testbot doesn't report a monitor, whereas XP on real machine does */
ok(broken(monitor_count == 0) || monitor_count > 0, "Expect at least one monitor found\n");
ret = EnumDisplayDevicesA(NULL, 0, &dd, 0);
ok(ret, "Expect success\n");
lstrcpyA(primary_device_name, dd.DeviceName);
primary_monitor_device_name[0] = 0;
ret = EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, (LPARAM)primary_monitor_device_name);
ok(ret, "EnumDisplayMonitors failed\n");
ok(!strcmp(primary_monitor_device_name, primary_device_name),
"monitor device name %s, device name %s\n", primary_monitor_device_name,
primary_device_name);
}
struct vid_mode
{
DWORD w, h, bpp, freq, fields;
BOOL must_succeed;
};
static const struct vid_mode vid_modes_test[] = {
{1024, 768, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY, 0},
{1024, 768, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY, 1},
{1024, 768, 0, 1, DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY, 0},
{1024, 768, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL , 0},
{1024, 768, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT , 1},
{1024, 768, 0, 0, DM_BITSPERPEL , 0},
{1024, 768, 0, 0, DM_DISPLAYFREQUENCY, 0},
{0, 0, 0, 0, DM_PELSWIDTH, 0},
{0, 0, 0, 0, DM_PELSHEIGHT, 0},
{1024, 768, 0, 0, DM_PELSWIDTH, 0},
{1024, 768, 0, 0, DM_PELSHEIGHT, 0},
{ 0, 768, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
{1024, 0, 0, 0, DM_PELSWIDTH | DM_PELSHEIGHT, 0},
/* the following test succeeds under XP SP3
{0, 0, 0, 0, DM_DISPLAYFREQUENCY, 0}
*/
};
struct device_info
{
DWORD index;
CHAR name[CCHDEVICENAME];
DEVMODEA original_mode;
};
#define expect_dm(a, b, c) _expect_dm(__LINE__, a, b, c)
static void _expect_dm(INT line, const DEVMODEA *expected, const CHAR *device, DWORD test)
{
DEVMODEA dm;
BOOL ret;
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
SetLastError(0xdeadbeef);
ret = EnumDisplaySettingsA(device, ENUM_CURRENT_SETTINGS, &dm);
ok_(__FILE__, line)(ret, "Device %s test %d EnumDisplaySettingsA failed, error %#x\n", device, test, GetLastError());
ok_(__FILE__, line)((dm.dmFields & expected->dmFields) == expected->dmFields,
"Device %s test %d expect dmFields to contain %#x, got %#x\n", device, test, expected->dmFields, dm.dmFields);
ok_(__FILE__, line)(!(expected->dmFields & DM_BITSPERPEL) || dm.dmBitsPerPel == expected->dmBitsPerPel,
"Device %s test %d expect dmBitsPerPel %u, got %u\n", device, test, expected->dmBitsPerPel, dm.dmBitsPerPel);
ok_(__FILE__, line)(!(expected->dmFields & DM_PELSWIDTH) || dm.dmPelsWidth == expected->dmPelsWidth,
"Device %s test %d expect dmPelsWidth %u, got %u\n", device, test, expected->dmPelsWidth, dm.dmPelsWidth);
ok_(__FILE__, line)(!(expected->dmFields & DM_PELSHEIGHT) || dm.dmPelsHeight == expected->dmPelsHeight,
"Device %s test %d expect dmPelsHeight %u, got %u\n", device, test, expected->dmPelsHeight, dm.dmPelsHeight);
ok_(__FILE__, line)(!(expected->dmFields & DM_POSITION) || dm.dmPosition.x == expected->dmPosition.x,
"Device %s test %d expect dmPosition.x %d, got %d\n", device, test, expected->dmPosition.x, dm.dmPosition.x);
ok_(__FILE__, line)(!(expected->dmFields & DM_POSITION) || dm.dmPosition.y == expected->dmPosition.y,
"Device %s test %d expect dmPosition.y %d, got %d\n", device, test, expected->dmPosition.y, dm.dmPosition.y);
ok_(__FILE__, line)(!(expected->dmFields & DM_DISPLAYFREQUENCY) ||
dm.dmDisplayFrequency == expected->dmDisplayFrequency,
"Device %s test %d expect dmDisplayFrequency %u, got %u\n", device, test, expected->dmDisplayFrequency,
dm.dmDisplayFrequency);
ok_(__FILE__, line)(!(expected->dmFields & DM_DISPLAYORIENTATION) ||
dm.dmDisplayOrientation == expected->dmDisplayOrientation,
"Device %s test %d expect dmDisplayOrientation %d, got %d\n", device, test, expected->dmDisplayOrientation,
dm.dmDisplayOrientation);
}
static void test_ChangeDisplaySettingsEx(void)
{
static const DWORD registry_fields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT |
DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY | DM_POSITION;
static const DWORD depths[] = {8, 16, 32};
DPI_AWARENESS_CONTEXT context = NULL;
UINT primary, device, test, mode;
UINT device_size, device_count;
struct device_info *devices;
DEVMODEA dm, dm2, dm3;
INT count, old_count;
DISPLAY_DEVICEA dd;
POINTL position;
DEVMODEW dmW;
BOOL found;
LONG res;
int i;
/* Test invalid device names */
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA failed, error %#x\n", GetLastError());
res = ChangeDisplaySettingsExA("invalid", &dm, NULL, CDS_TEST, NULL);
ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res);
res = ChangeDisplaySettingsExA("\\\\.\\DISPLAY0", &dm, NULL, CDS_TEST, NULL);
ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res);
res = ChangeDisplaySettingsExA("\\\\.\\DISPLAY1\\Monitor0", &dm, NULL, CDS_TEST, NULL);
ok(res == DISP_CHANGE_BADPARAM, "ChangeDisplaySettingsA returned unexpected %d\n", res);
/* Test dmDriverExtra */
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA failed, error %#x\n", GetLastError());
memset(&dmW, 0, sizeof(dmW));
dmW.dmSize = sizeof(dmW);
res = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &dmW);
ok(res, "EnumDisplaySettingsW failed, error %#x\n", GetLastError());
/* ChangeDisplaySettingsA/W reset dmDriverExtra to 0 */
dm.dmDriverExtra = 1;
res = ChangeDisplaySettingsA(&dm, CDS_TEST);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsA returned unexpected %d\n", res);
ok(dm.dmDriverExtra == 0, "ChangeDisplaySettingsA didn't reset dmDriverExtra to 0\n");
dmW.dmDriverExtra = 1;
res = ChangeDisplaySettingsW(&dmW, CDS_TEST);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW returned unexpected %d\n", res);
ok(dmW.dmDriverExtra == 0, "ChangeDisplaySettingsW didn't reset dmDriverExtra to 0\n");
/* ChangeDisplaySettingsExA/W do not modify dmDriverExtra */
dm.dmDriverExtra = 1;
res = ChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA returned unexpected %d\n", res);
ok(dm.dmDriverExtra == 1, "ChangeDisplaySettingsExA shouldn't change dmDriverExtra\n");
dmW.dmDriverExtra = 1;
res = ChangeDisplaySettingsExW(NULL, &dmW, NULL, CDS_TEST, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW returned unexpected %d\n", res);
ok(dmW.dmDriverExtra == 1, "ChangeDisplaySettingsExW shouldn't change dmDriverExtra\n");
/* Test dmSize */
/* ChangeDisplaySettingsA/ExA report success even if dmSize is 0 */
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA failed, error %#x\n", GetLastError());
dm.dmSize = 0;
res = ChangeDisplaySettingsA(&dm, CDS_TEST);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsA returned unexpected %d\n", res);
dm.dmSize = 0;
res = ChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA returned unexpected %d\n", res);
/* dmSize for ChangeDisplaySettingsW/ExW needs to be at least FIELD_OFFSET(DEVMODEW, dmICMMethod) */
memset(&dmW, 0, sizeof(dmW));
dmW.dmSize = sizeof(dmW);
res = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &dmW);
ok(res, "EnumDisplaySettingsW failed, error %#x\n", GetLastError());
dmW.dmSize = FIELD_OFFSET(DEVMODEW, dmICMMethod) - 1;
res = ChangeDisplaySettingsW(&dmW, CDS_TEST);
ok(res == DISP_CHANGE_BADMODE, "ChangeDisplaySettingsW returned %d, expect DISP_CHANGE_BADMODE\n", res);
dmW.dmSize = FIELD_OFFSET(DEVMODEW, dmICMMethod) - 1;
res = ChangeDisplaySettingsExW(NULL, &dmW, NULL, CDS_TEST, NULL);
ok(res == DISP_CHANGE_BADMODE, "ChangeDisplaySettingsExW returned %d, expect DISP_CHANGE_BADMODE\n", res);
dmW.dmSize = FIELD_OFFSET(DEVMODEW, dmICMMethod);
res = ChangeDisplaySettingsW(&dmW, CDS_TEST);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW returned unexpected %d\n", res);
dmW.dmSize = FIELD_OFFSET(DEVMODEW, dmICMMethod);
res = ChangeDisplaySettingsExW(NULL, &dmW, NULL, CDS_TEST, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW returned unexpected %d\n", res);
/* Test clip rectangle after resolution changes */
/* GetClipCursor always returns result in physical pixels but GetSystemMetrics(SM_CX/CYVIRTUALSCREEN) are not.
* Set per-monitor aware context so that virtual screen rectangles are in physical pixels */
if (pSetThreadDpiAwarenessContext)
context = pSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
for (i = 0; i < ARRAY_SIZE(vid_modes_test); i++)
{
dm.dmPelsWidth = vid_modes_test[i].w;
dm.dmPelsHeight = vid_modes_test[i].h;
dm.dmBitsPerPel = vid_modes_test[i].bpp;
dm.dmDisplayFrequency = vid_modes_test[i].freq;
dm.dmFields = vid_modes_test[i].fields;
res = ChangeDisplaySettingsExA(NULL, &dm, NULL, CDS_TEST, NULL);
ok(vid_modes_test[i].must_succeed ?
(res == DISP_CHANGE_SUCCESSFUL || res == DISP_CHANGE_RESTART) :
(res == DISP_CHANGE_SUCCESSFUL || res == DISP_CHANGE_RESTART ||
res == DISP_CHANGE_BADMODE || res == DISP_CHANGE_BADPARAM),
"Unexpected ChangeDisplaySettingsExA() return code for vid_modes_test[%d]: %d\n", i, res);
if (res == DISP_CHANGE_SUCCESSFUL)
{
RECT r, r1, virt;
SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
if (IsRectEmpty(&virt)) /* NT4 doesn't have SM_CX/YVIRTUALSCREEN */
SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
/* Resolution change resets clip rect */
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
ok(EqualRect(&r, &virt), "Invalid clip rect: %s\n", wine_dbgstr_rect(&r));
if (!ClipCursor(NULL)) continue;
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
ok(EqualRect(&r, &virt), "Invalid clip rect: %s\n", wine_dbgstr_rect(&r));
/* This should always work. Primary monitor is at (0,0) */
SetRect(&r1, 10, 10, 20, 20);
ok(ClipCursor(&r1), "ClipCursor() failed\n");
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
ok(EqualRect(&r, &r1), "Invalid clip rect: %s\n", wine_dbgstr_rect(&r));
SetRect(&r1, 10, 10, 10, 10);
ok(ClipCursor(&r1), "ClipCursor() failed\n");
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
ok(EqualRect(&r, &r1), "Invalid clip rect: %s\n", wine_dbgstr_rect(&r));
SetRect(&r1, 10, 10, 10, 9);
ok(!ClipCursor(&r1), "ClipCursor() succeeded\n");
/* Windows bug: further clipping fails once an empty rect is set, so we have to reset it */
ClipCursor(NULL);
SetRect(&r1, virt.left - 10, virt.top - 10, virt.right + 20, virt.bottom + 20);
ok(ClipCursor(&r1), "ClipCursor() failed\n");
ok(GetClipCursor(&r), "GetClipCursor() failed\n");
ok(EqualRect(&r, &virt) || broken(EqualRect(&r, &r1)) /* win9x */,
"Invalid clip rect: %s\n", wine_dbgstr_rect(&r));
ClipCursor(&virt);
}
}
if (pSetThreadDpiAwarenessContext && context)
pSetThreadDpiAwarenessContext(context);
res = ChangeDisplaySettingsExA(NULL, NULL, NULL, CDS_RESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "Failed to reset default resolution: %d\n", res);
/* Save the original mode for all devices so that they can be restored at the end of tests */
device_count = 0;
device_size = 2;
devices = heap_calloc(device_size, sizeof(*devices));
ok(devices != NULL, "Failed to allocate memory.\n");
primary = 0;
memset(&dd, 0, sizeof(dd));
dd.cb = sizeof(dd);
for (device = 0; EnumDisplayDevicesA(NULL, device, &dd, 0); ++device)
{
INT number;
/* Skip software devices */
if (sscanf(dd.DeviceName, "\\\\.\\DISPLAY%d", &number) != 1)
continue;
if (!(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
continue;
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
primary = device_count;
if (device_count >= device_size)
{
device_size *= 2;
devices = heap_realloc(devices, device_size * sizeof(*devices));
ok(devices != NULL, "Failed to reallocate memory.\n");
}
devices[device_count].index = device;
lstrcpyA(devices[device_count].name, dd.DeviceName);
memset(&devices[device_count].original_mode, 0, sizeof(devices[device_count].original_mode));
devices[device_count].original_mode.dmSize = sizeof(devices[device_count].original_mode);
res = EnumDisplaySettingsA(dd.DeviceName, ENUM_CURRENT_SETTINGS, &devices[device_count].original_mode);
ok(res, "EnumDisplaySettingsA %s failed, error %#x\n", dd.DeviceName, GetLastError());
++device_count;
}
/* Make the primary adapter first */
if (primary)
{
struct device_info tmp;
tmp = devices[0];
devices[0] = devices[primary];
devices[primary] = tmp;
}
/* Test detaching adapters */
/* Test that when there is only one adapter, it can't be detached */
if (device_count == 1)
{
old_count = GetSystemMetrics(SM_CMONITORS);
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
dm.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
dm.dmPosition = devices[0].original_mode.dmPosition;
res = ChangeDisplaySettingsExA(devices[0].name, &dm, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[0].name, res);
res = ChangeDisplaySettingsExA(NULL, NULL, NULL, 0, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL ||
broken(res == DISP_CHANGE_FAILED), /* win8 TestBot */
"ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[0].name, res);
/* Check that the adapter is still attached */
dd.cb = sizeof(dd);
res = EnumDisplayDevicesA(NULL, devices[0].index, &dd, 0);
ok(res, "EnumDisplayDevicesA %s failed, error %#x\n", devices[0].name, GetLastError());
ok(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP, "Expect device %s still attached.\n", devices[0].name);
count = GetSystemMetrics(SM_CMONITORS);
ok(count == old_count, "Expect monitor count %d, got %d\n", old_count, count);
/* Restore registry settings */
res = ChangeDisplaySettingsExA(devices[0].name, &devices[0].original_mode, NULL,
CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL ||
broken(res == DISP_CHANGE_BADPARAM) || /* win10 */
broken(res == DISP_CHANGE_FAILED), /* win8 TestBot */
"ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[0].name, res);
res = ChangeDisplaySettingsExA(NULL, NULL, NULL, 0, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL ||
broken(res == DISP_CHANGE_FAILED), /* win8 TestBot */
"ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[0].name, res);
}
/* Test that only specifying DM_POSITION in dmFields is not enough to detach an adapter */
if (device_count >= 2)
{
old_count = GetSystemMetrics(SM_CMONITORS);
/* MSDN says set dmFields to DM_POSITION to detach, but DM_PELSWIDTH and DM_PELSHEIGHT are needed actually.
* To successfully detach adapters, settings have to be saved to the registry first, and then call
* ChangeDisplaySettingsExA(device, NULL, NULL, 0, NULL) to update settings. Otherwise on some older versions
* of Windows, e.g., XP and Win7, the adapter doesn't get detached */
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
dm.dmFields = DM_POSITION;
dm.dmPosition = devices[1].original_mode.dmPosition;
res = ChangeDisplaySettingsExA(devices[1].name, &dm, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[1].name, res);
res = ChangeDisplaySettingsExA(devices[1].name, NULL, NULL, 0, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[1].name, res);
dd.cb = sizeof(dd);
res = EnumDisplayDevicesA(NULL, devices[1].index, &dd, 0);
ok(res, "EnumDisplayDevicesA %s failed, error %#x\n", devices[1].name, GetLastError());
ok(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP, "Expect device %s still attached.\n", devices[1].name);
count = GetSystemMetrics(SM_CMONITORS);
ok(count == old_count, "Expect monitor count %d, got %d\n", old_count, count);
}
/* Test changing to a mode with depth set but with zero width and height */
for (device = 0; device < device_count; ++device)
{
for (test = 0; test < ARRAY_SIZE(depths); ++test)
{
/* Find the native resolution */
memset(&dm, 0, sizeof(dm));
memset(&dm2, 0, sizeof(dm2));
dm2.dmSize = sizeof(dm2);
for (mode = 0; EnumDisplaySettingsExA(devices[device].name, mode, &dm2, 0); ++mode)
{
if (dm2.dmBitsPerPel == depths[test]
&& dm2.dmPelsWidth > dm.dmPelsWidth && dm2.dmPelsHeight > dm.dmPelsHeight)
dm = dm2;
}
if (dm.dmBitsPerPel != depths[test])
{
skip("Depth %u is unsupported for %s.\n", depths[test], devices[device].name);
continue;
}
/* Find the second resolution */
memset(&dm2, 0, sizeof(dm2));
dm2.dmSize = sizeof(dm2);
for (mode = 0; EnumDisplaySettingsExA(devices[device].name, mode, &dm2, 0); ++mode)
{
if (dm2.dmBitsPerPel == depths[test]
&& dm2.dmPelsWidth != dm.dmPelsWidth && dm2.dmPelsHeight != dm.dmPelsHeight)
break;
}
if (dm2.dmBitsPerPel != depths[test]
|| dm2.dmPelsWidth == dm.dmPelsWidth || dm2.dmPelsHeight == dm.dmPelsHeight)
{
skip("Failed to find the second mode for %s.\n", devices[device].name);
continue;
}
/* Find the third resolution */
memset(&dm3, 0, sizeof(dm3));
dm3.dmSize = sizeof(dm3);
for (mode = 0; EnumDisplaySettingsExA(devices[device].name, mode, &dm3, 0); ++mode)
{
if (dm3.dmBitsPerPel == depths[test]
&& dm3.dmPelsWidth != dm.dmPelsWidth && dm3.dmPelsHeight != dm.dmPelsHeight
&& dm3.dmPelsWidth != dm2.dmPelsWidth && dm3.dmPelsHeight != dm2.dmPelsHeight)
break;
}
if (dm3.dmBitsPerPel != depths[test]
|| dm3.dmPelsWidth == dm.dmPelsWidth || dm3.dmPelsHeight == dm.dmPelsHeight
|| dm3.dmPelsWidth == dm2.dmPelsWidth || dm3.dmPelsHeight == dm2.dmPelsHeight)
{
skip("Failed to find the third mode for %s.\n", devices[device].name);
continue;
}
/* Change the current mode to the third mode first */
res = ChangeDisplaySettingsExA(devices[device].name, &dm3, NULL, CDS_RESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL
|| broken(res == DISP_CHANGE_FAILED), /* Win8 TestBots */
"ChangeDisplaySettingsExA %s returned unexpected %d.\n", devices[device].name, res);
if (res != DISP_CHANGE_SUCCESSFUL)
{
win_skip("Failed to change display mode for %s.\n", devices[device].name);
continue;
}
flush_events();
expect_dm(&dm3, devices[device].name, test);
/* Change the registry mode to the second mode */
res = ChangeDisplaySettingsExA(devices[device].name, &dm2, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL
|| broken(res == DISP_CHANGE_BADFLAGS), /* Win10 32bit */
"ChangeDisplaySettingsExA %s returned unexpected %d.\n", devices[device].name, res);
/* Change to a mode with depth set but with zero width and height */
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
dm.dmBitsPerPel = depths[test];
res = ChangeDisplaySettingsExA(devices[device].name, &dm, NULL, CDS_RESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d.\n",
devices[device].name, res);
flush_events();
dd.cb = sizeof(dd);
res = EnumDisplayDevicesA(NULL, devices[device].index, &dd, 0);
ok(res, "EnumDisplayDevicesA %s failed, error %#x.\n", devices[device].name, GetLastError());
ok(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP, "Expect %s attached.\n",
devices[device].name);
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(devices[device].name, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "Device %s EnumDisplaySettingsA failed, error %#x.\n", devices[device].name, GetLastError());
ok(dm.dmBitsPerPel == depths[test], "Device %s expect dmBitsPerPel %u, got %u.\n",
devices[device].name, depths[test], dm.dmBitsPerPel);
/* 2008 resets to the resolution in the registry. Newer versions of Windows doesn't
* change the current resolution */
ok(dm.dmPelsWidth == dm3.dmPelsWidth || broken(dm.dmPelsWidth == dm2.dmPelsWidth),
"Device %s expect dmPelsWidth %u, got %u.\n",
devices[device].name, dm3.dmPelsWidth, dm.dmPelsWidth);
ok(dm.dmPelsHeight == dm3.dmPelsHeight || broken(dm.dmPelsHeight == dm2.dmPelsHeight),
"Device %s expect dmPelsHeight %u, got %u.\n",
devices[device].name, dm3.dmPelsHeight, dm.dmPelsHeight);
}
}
/* Detach all non-primary adapters to avoid position conflicts */
for (device = 1; device < device_count; ++device)
{
old_count = GetSystemMetrics(SM_CMONITORS);
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
dm.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
dm.dmPosition = devices[device].original_mode.dmPosition;
res = ChangeDisplaySettingsExA(devices[device].name, &dm, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[device].name, res);
res = ChangeDisplaySettingsExA(devices[device].name, NULL, NULL, 0, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[device].name, res);
dd.cb = sizeof(dd);
res = EnumDisplayDevicesA(NULL, devices[device].index, &dd, 0);
ok(res, "EnumDisplayDevicesA %s failed, error %#x\n", devices[device].name, GetLastError());
ok(!(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP), "Expect device %s detached.\n", devices[device].name);
count = GetSystemMetrics(SM_CMONITORS);
ok(count == old_count - 1, "Expect monitor count %d, got %d\n", old_count - 1, count);
}
/* Test changing each adapter to different width, height, frequency and depth */
position.x = 0;
position.y = 0;
for (device = 0; device < device_count; ++device)
{
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
for (mode = 0; EnumDisplaySettingsExA(devices[device].name, mode, &dm, 0); ++mode)
{
if (mode == 0)
{
dm2 = dm;
}
else
{
found = FALSE;
if (dm2.dmPelsWidth && dm.dmPelsWidth != dm2.dmPelsWidth)
{
dm2.dmPelsWidth = 0;
found = TRUE;
}
if (dm2.dmPelsHeight && dm.dmPelsHeight != dm2.dmPelsHeight)
{
dm2.dmPelsHeight = 0;
found = TRUE;
}
if (dm2.dmDisplayFrequency && dm.dmDisplayFrequency != dm2.dmDisplayFrequency)
{
dm2.dmDisplayFrequency = 0;
found = TRUE;
}
if (dm2.dmBitsPerPel && dm.dmBitsPerPel != dm2.dmBitsPerPel)
{
dm2.dmBitsPerPel = 0;
found = TRUE;
}
if (!dm2.dmPelsWidth && !dm2.dmPelsHeight && !dm2.dmDisplayFrequency
&& !dm2.dmBitsPerPel)
break;
if (!found)
continue;
}
dm.dmPosition = position;
dm.dmFields |= DM_POSITION;
/* Reattach detached non-primary adapters, otherwise ChangeDisplaySettingsExA with only CDS_RESET fails */
if (mode == 0 && device)
{
res = ChangeDisplaySettingsExA(devices[device].name, &dm, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s mode %d returned unexpected %d\n",
devices[device].name, mode, res);
res = ChangeDisplaySettingsExA(NULL, NULL, NULL, 0, NULL);
}
else
{
res = ChangeDisplaySettingsExA(devices[device].name, &dm, NULL, CDS_RESET, NULL);
}
ok(res == DISP_CHANGE_SUCCESSFUL ||
broken(res == DISP_CHANGE_FAILED), /* TestBots using VGA driver can't change to some modes */
"ChangeDisplaySettingsExA %s mode %d returned unexpected %d\n", devices[device].name, mode, res);
if (res != DISP_CHANGE_SUCCESSFUL)
{
win_skip("Failed to change %s to mode %d.\n", devices[device].name, mode);
continue;
}
flush_events();
expect_dm(&dm, devices[device].name, mode);
}
/* Restore settings */
res = ChangeDisplaySettingsExA(devices[device].name, NULL, NULL, 0, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL ||
broken(res == DISP_CHANGE_FAILED), /* win8 TestBot */
"ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[device].name, res);
/* Place the next adapter to the right so that there is no position conflict */
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(devices[device].name, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA %s failed, error %#x\n", devices[device].name, GetLastError());
position.x = dm.dmPosition.x + dm.dmPelsWidth;
}
/* Test changing modes by saving settings to the registry first */
for (device = 0; device < device_count; ++device)
{
/* Place adapter to the right */
if (device == 0)
{
position.x = 0;
position.y = 0;
}
else
{
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(devices[device - 1].name, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA %s failed, error %#x.\n", devices[device - 1].name, GetLastError());
position.x = dm.dmPosition.x + dm.dmPelsWidth;
}
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(devices[device].name, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA %s failed, error %#x\n", devices[device].name, GetLastError());
dm3 = dm;
/* Find a mode that's different from the current mode */
memset(&dm2, 0, sizeof(dm2));
dm2.dmSize = sizeof(dm2);
for (mode = 0; EnumDisplaySettingsA(devices[device].name, mode, &dm2); ++mode)
{
/* Use the same color depth because the win2008 TestBots are unable to change it */
if (dm2.dmPelsWidth != dm.dmPelsWidth && dm2.dmPelsHeight != dm.dmPelsHeight &&
dm2.dmBitsPerPel == dm.dmBitsPerPel)
break;
}
ok(dm2.dmPelsWidth != dm.dmPelsWidth && dm2.dmPelsHeight != dm.dmPelsHeight &&
dm2.dmBitsPerPel == dm.dmBitsPerPel, "Failed to find a different mode.\n");
/* Test normal operation */
dm = dm2;
dm.dmFields |= DM_POSITION;
dm.dmPosition = position;
res = ChangeDisplaySettingsExA(devices[device].name, &dm, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL ||
broken(res == DISP_CHANGE_FAILED), /* win8 TestBot */
"ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[device].name, res);
res = ChangeDisplaySettingsExA(devices[device].name, NULL, NULL, 0, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL ||
broken(res == DISP_CHANGE_FAILED), /* win8 TestBot */
"ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[device].name, res);
if (res != DISP_CHANGE_SUCCESSFUL)
{
win_skip("Failed to change mode for %s.\n", devices[device].name);
continue;
}
flush_events();
expect_dm(&dm, devices[device].name, 0);
/* Test specifying only position, width and height */
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
dm.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
dm.dmPosition = position;
dm.dmPelsWidth = dm3.dmPelsWidth;
dm.dmPelsHeight = dm3.dmPelsHeight;
res = ChangeDisplaySettingsExA(devices[device].name, &dm, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned %d.\n", devices[device].name, res);
res = EnumDisplaySettingsA(devices[device].name, ENUM_REGISTRY_SETTINGS, &dm);
/* Win10 either returns failure here or retrieves outdated display settings until they're applied */
if (res)
{
ok((dm.dmFields & registry_fields) == registry_fields, "Got unexpected dmFields %#x.\n", dm.dmFields);
ok(dm.dmPosition.x == position.x, "Expected dmPosition.x %d, got %d.\n", position.x, dm.dmPosition.x);
ok(dm.dmPosition.y == position.y, "Expected dmPosition.y %d, got %d.\n", position.y, dm.dmPosition.y);
ok(dm.dmPelsWidth == dm3.dmPelsWidth || broken(dm.dmPelsWidth == dm2.dmPelsWidth), /* Win10 */
"Expected dmPelsWidth %u, got %u.\n", dm3.dmPelsWidth, dm.dmPelsWidth);
ok(dm.dmPelsHeight == dm3.dmPelsHeight || broken(dm.dmPelsHeight == dm2.dmPelsHeight), /* Win10 */
"Expected dmPelsHeight %u, got %u.\n", dm3.dmPelsHeight, dm.dmPelsHeight);
ok(dm.dmBitsPerPel, "Expected dmBitsPerPel not zero.\n");
ok(dm.dmDisplayFrequency, "Expected dmDisplayFrequency not zero.\n");
}
else
{
win_skip("EnumDisplaySettingsA %s failed, error %#x.\n", devices[device].name, GetLastError());
}
res = ChangeDisplaySettingsExA(devices[device].name, NULL, NULL, 0, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned %d.\n", devices[device].name, res);
flush_events();
res = EnumDisplaySettingsA(devices[device].name, ENUM_REGISTRY_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA %s failed, error %#x.\n", devices[device].name, GetLastError());
ok((dm.dmFields & registry_fields) == registry_fields, "Got unexpected dmFields %#x.\n", dm.dmFields);
ok(dm.dmPosition.x == position.x, "Expected dmPosition.x %d, got %d.\n", position.x, dm.dmPosition.x);
ok(dm.dmPosition.y == position.y, "Expected dmPosition.y %d, got %d.\n", position.y, dm.dmPosition.y);
ok(dm.dmPelsWidth == dm3.dmPelsWidth, "Expected dmPelsWidth %u, got %u.\n", dm3.dmPelsWidth, dm.dmPelsWidth);
ok(dm.dmPelsHeight == dm3.dmPelsHeight, "Expected dmPelsHeight %u, got %u.\n", dm3.dmPelsHeight,
dm.dmPelsHeight);
ok(dm.dmBitsPerPel, "Expected dmBitsPerPel not zero.\n");
ok(dm.dmDisplayFrequency, "Expected dmDisplayFrequency not zero.\n");
expect_dm(&dm, devices[device].name, 0);
}
/* Test dmPosition */
/* First detach all adapters except for the primary and secondary adapters to avoid position conflicts */
if (device_count >= 3)
{
for (device = 2; device < device_count; ++device)
{
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(devices[device].name, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA %s failed, error %#x\n", devices[device].name, GetLastError());
dm.dmPelsWidth = 0;
dm.dmPelsHeight = 0;
dm.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
res = ChangeDisplaySettingsExA(devices[device].name, &dm, NULL, CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[device].name, res);
}
res = ChangeDisplaySettingsExA(NULL, NULL, NULL, 0, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA returned unexpected %d\n", res);
}
if (device_count >= 2)
{
/* Query the primary adapter settings */
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
res = EnumDisplaySettingsA(devices[0].name, ENUM_CURRENT_SETTINGS, &dm);
ok(res, "EnumDisplaySettingsA %s failed, error %#x\n", devices[0].name, GetLastError());
if (res)
{
/* Query the secondary adapter settings */
memset(&dm2, 0, sizeof(dm2));
dm2.dmSize = sizeof(dm2);
res = EnumDisplaySettingsA(devices[1].name, ENUM_CURRENT_SETTINGS, &dm2);
ok(res, "EnumDisplaySettingsA %s failed, error %#x\n", devices[1].name, GetLastError());
}
if (res)
{
/* The secondary adapter should be to the right of the primary adapter */
ok(dm2.dmPosition.x == dm.dmPosition.x + dm.dmPelsWidth,
"Expected dm2.dmPosition.x %d, got %d.\n", dm.dmPosition.x + dm.dmPelsWidth,
dm2.dmPosition.x);
ok(dm2.dmPosition.y == dm.dmPosition.y, "Expected dm2.dmPosition.y %d, got %d.\n",
dm.dmPosition.y, dm2.dmPosition.y);
/* Test position conflict */
dm2.dmPosition.x = dm.dmPosition.x - dm2.dmPelsWidth + 1;
dm2.dmPosition.y = dm.dmPosition.y;
res = ChangeDisplaySettingsExA(devices[1].name, &dm2, NULL, CDS_RESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[1].name, res);
/* Position is changed and automatically moved */
memset(&dm2, 0, sizeof(dm2));
dm2.dmSize = sizeof(dm2);
res = EnumDisplaySettingsA(devices[1].name, ENUM_CURRENT_SETTINGS, &dm2);
ok(res, "EnumDisplaySettingsA %s failed, error %#x\n", devices[1].name, GetLastError());
ok(dm2.dmPosition.x == dm.dmPosition.x - dm2.dmPelsWidth,
"Expected dmPosition.x %d, got %d.\n", dm.dmPosition.x - dm2.dmPelsWidth,
dm2.dmPosition.x);
/* Test position with extra space. The extra space will be removed */
dm2.dmPosition.x = dm.dmPosition.x + dm.dmPelsWidth + 1;
dm2.dmPosition.y = dm.dmPosition.y;
res = ChangeDisplaySettingsExA(devices[1].name, &dm2, NULL, CDS_RESET, NULL);
ok(res == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExA %s returned unexpected %d\n", devices[1].name, res);
dm2.dmPosition.x = dm.dmPosition.x + dm.dmPelsWidth;
expect_dm(&dm2, devices[1].name, 0);
/* Test placing the secondary adapter to all sides of the primary adapter */