ReactOS  0.4.15-dev-5142-g967f5b9
display.c File Reference
#include <win32k.h>
Include dependency graph for display.c:

Go to the source code of this file.

Macros

#define READ(field, str, flag)
 

Functions

 DBG_DEFAULT_CHANNEL (UserDisplay)
 
VOID RegWriteDisplaySettings (HKEY hkey, PDEVMODEW pdm)
 
VOID RegReadDisplaySettings (HKEY hkey, PDEVMODEW pdm)
 
PGRAPHICS_DEVICE NTAPI InitDisplayDriver (IN PWSTR pwszDeviceName, IN PWSTR pwszRegKey)
 
NTSTATUS NTAPI InitVideo (VOID)
 
VOID UserRefreshDisplay (IN PPDEVOBJ ppdev)
 
NTSTATUS NTAPI UserEnumDisplayDevices (PUNICODE_STRING pustrDevice, DWORD iDevNum, PDISPLAY_DEVICEW pdispdev, DWORD dwFlags)
 
BOOL NTAPI NtUserEnumDisplayDevices (PUNICODE_STRING pustrDevice, DWORD iDevNum, PDISPLAY_DEVICEW pDisplayDevice, DWORD dwFlags)
 
NTSTATUS NTAPI UserEnumCurrentDisplaySettings (PUNICODE_STRING pustrDevice, PDEVMODEW *ppdm)
 
NTSTATUS NTAPI UserEnumDisplaySettings (PUNICODE_STRING pustrDevice, DWORD iModeNum, LPDEVMODEW *ppdm, DWORD dwFlags)
 
NTSTATUS NTAPI UserOpenDisplaySettingsKey (OUT PHKEY phkey, IN PUNICODE_STRING pustrDevice, IN BOOL bGlobal)
 
NTSTATUS NTAPI UserEnumRegistryDisplaySettings (IN PUNICODE_STRING pustrDevice, OUT LPDEVMODEW pdm)
 
NTSTATUS APIENTRY NtUserEnumDisplaySettings (IN PUNICODE_STRING pustrDevice, IN DWORD iModeNum, OUT LPDEVMODEW lpDevMode, IN DWORD dwFlags)
 
VOID UserUpdateFullscreen (DWORD flags)
 
LONG APIENTRY UserChangeDisplaySettings (PUNICODE_STRING pustrDevice, LPDEVMODEW pdm, DWORD flags, LPVOID lParam)
 
VOID UserDisplayNotifyShutdown (PPROCESSINFO ppiCurrent)
 
LONG APIENTRY NtUserChangeDisplaySettings (PUNICODE_STRING pustrDevice, LPDEVMODEW lpDevMode, DWORD dwflags, LPVOID lParam)
 

Variables

BOOL gbBaseVideo = FALSE
 
static PPROCESSINFO gpFullscreen = NULL
 
static const PWCHAR KEY_VIDEO = L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO"
 

Macro Definition Documentation

◆ READ

#define READ (   field,
  str,
  flag 
)
Value:
if (RegReadDWORD(hkey, L##str, &dwValue)) \
{ \
pdm->field = dwValue; \
pdm->dmFields |= flag; \
}
#define L(x)
Definition: ntvdm.h:50
const WCHAR * str
BOOL NTAPI RegReadDWORD(HKEY hkey, PWSTR pwszValue, PDWORD pdwData)
Definition: registry.c:150
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 flag
Definition: glfuncs.h:52

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserDisplay  )

◆ InitDisplayDriver()

PGRAPHICS_DEVICE NTAPI InitDisplayDriver ( IN PWSTR  pwszDeviceName,
IN PWSTR  pwszRegKey 
)

Definition at line 66 of file display.c.

69 {
70  PGRAPHICS_DEVICE pGraphicsDevice;
71  UNICODE_STRING ustrDeviceName, ustrDisplayDrivers, ustrDescription;
73  WCHAR awcBuffer[128];
74  ULONG cbSize;
75  HKEY hkey;
76  DWORD dwVga;
77 
78  TRACE("InitDisplayDriver(%S, %S);\n",
79  pwszDeviceName, pwszRegKey);
80 
81  /* Open the driver's registry key */
82  Status = RegOpenKey(pwszRegKey, &hkey);
83  if (!NT_SUCCESS(Status))
84  {
85  ERR("Failed to open registry key: %ls\n", pwszRegKey);
86  return NULL;
87  }
88 
89  /* Query the diplay drivers */
90  cbSize = sizeof(awcBuffer) - 10;
91  Status = RegQueryValue(hkey,
92  L"InstalledDisplayDrivers",
94  awcBuffer,
95  &cbSize);
96  if (!NT_SUCCESS(Status))
97  {
98  ERR("Didn't find 'InstalledDisplayDrivers', status = 0x%lx\n", Status);
99  ZwClose(hkey);
100  return NULL;
101  }
102 
103  /* Initialize the UNICODE_STRING */
104  ustrDisplayDrivers.Buffer = awcBuffer;
105  ustrDisplayDrivers.MaximumLength = (USHORT)cbSize;
106  ustrDisplayDrivers.Length = (USHORT)cbSize;
107 
108  /* Set Buffer for description and size of remaining buffer */
109  ustrDescription.Buffer = awcBuffer + (cbSize / sizeof(WCHAR));
110  cbSize = sizeof(awcBuffer) - cbSize;
111 
112  /* Query the device string */
113  Status = RegQueryValue(hkey,
114  L"Device Description",
115  REG_SZ,
116  ustrDescription.Buffer,
117  &cbSize);
118  if (NT_SUCCESS(Status))
119  {
120  ustrDescription.MaximumLength = (USHORT)cbSize;
121  ustrDescription.Length = (USHORT)cbSize;
122  }
123  else
124  {
125  RtlInitUnicodeString(&ustrDescription, L"<unknown>");
126  }
127 
128  /* Query if this is a VGA compatible driver */
129  cbSize = sizeof(DWORD);
130  Status = RegQueryValue(hkey, L"VgaCompatible", REG_DWORD, &dwVga, &cbSize);
131  if (!NT_SUCCESS(Status)) dwVga = 0;
132 
133  /* Close the registry key */
134  ZwClose(hkey);
135 
136  /* Register the device with GDI */
137  RtlInitUnicodeString(&ustrDeviceName, pwszDeviceName);
138  pGraphicsDevice = EngpRegisterGraphicsDevice(&ustrDeviceName,
139  &ustrDisplayDrivers,
140  &ustrDescription);
141  if (pGraphicsDevice && dwVga)
142  {
143  pGraphicsDevice->StateFlags |= DISPLAY_DEVICE_VGA_COMPATIBLE;
144  }
145 
146  return pGraphicsDevice;
147 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
DWORD StateFlags
Definition: pdevobj.h:66
LONG NTSTATUS
Definition: precomp.h:26
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define REG_MULTI_SZ
Definition: nt_native.h:1501
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR pwszDeviceName
Definition: winddi.h:3553
#define ERR(fmt,...)
Definition: debug.h:110
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
#define DISPLAY_DEVICE_VGA_COMPATIBLE
Definition: wingdi.h:1400
#define RegQueryValue
Definition: winreg.h:523
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PGRAPHICS_DEVICE NTAPI EngpRegisterGraphicsDevice(_In_ PUNICODE_STRING pustrDeviceName, _In_ PUNICODE_STRING pustrDiplayDrivers, _In_ PUNICODE_STRING pustrDescription)
Definition: device.c:311
#define RegOpenKey
Definition: winreg.h:519
#define REG_DWORD
Definition: sdbapi.c:596
#define REG_SZ
Definition: layer.c:22

Referenced by EngpUpdateGraphicsDeviceList().

◆ InitVideo()

NTSTATUS NTAPI InitVideo ( VOID  )

Definition at line 151 of file display.c.

152 {
154  HKEY hkey;
155 
156  TRACE("----------------------------- InitVideo() -------------------------------\n");
157 
158  /* Check if VGA mode is requested, by finding the special volatile key created by VIDEOPRT */
159  Status = RegOpenKey(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\GraphicsDrivers\\BaseVideo", &hkey);
160  if (NT_SUCCESS(Status))
161  ZwClose(hkey);
163  if (gbBaseVideo)
164  ERR("VGA mode requested.\n");
165 
166  /* Initialize all display devices */
168  if (!NT_SUCCESS(Status))
169  return Status;
170 
171  /* Check if we had any success */
173  {
174  /* Check if there is a VGA device we skipped */
176  {
177  /* There is, use the VGA device */
179  }
180  else
181  {
182  ERR("No usable display driver was found.\n");
183  return STATUS_UNSUCCESSFUL;
184  }
185  }
186 
187  InitSysParams();
188 
189  return STATUS_SUCCESS;
190 }
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
PGRAPHICS_DEVICE gpVgaGraphicsDevice
Definition: device.c:16
PGRAPHICS_DEVICE gpPrimaryGraphicsDevice
Definition: device.c:15
#define L(x)
Definition: ntvdm.h:50
BOOL InitSysParams(VOID)
Definition: sysparams.c:350
BOOL gbBaseVideo
Definition: display.c:12
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ERR(fmt,...)
Definition: debug.h:110
NTSTATUS EngpUpdateGraphicsDeviceList(VOID)
Definition: device.c:36
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RegOpenKey
Definition: winreg.h:519

Referenced by UserInitialize().

◆ NtUserChangeDisplaySettings()

LONG APIENTRY NtUserChangeDisplaySettings ( PUNICODE_STRING  pustrDevice,
LPDEVMODEW  lpDevMode,
DWORD  dwflags,
LPVOID  lParam 
)

Definition at line 946 of file display.c.

951 {
952  WCHAR awcDevice[CCHDEVICENAME];
953  UNICODE_STRING ustrDevice;
954  DEVMODEW dmLocal;
955  LONG lRet;
956 
957  /* Check arguments */
958  if ((dwflags != CDS_VIDEOPARAMETERS) && (lParam != NULL))
959  {
961  return DISP_CHANGE_BADPARAM;
962  }
963 
964  /* Check flags */
966  {
967  return DISP_CHANGE_BADFLAGS;
968  }
969 
970  if ((dwflags & CDS_RESET) && (dwflags & CDS_NORESET))
971  {
972  return DISP_CHANGE_BADFLAGS;
973  }
974 
975  /* Copy the device name */
976  if (pustrDevice)
977  {
978  /* Initialize destination string */
979  RtlInitEmptyUnicodeString(&ustrDevice, awcDevice, sizeof(awcDevice));
980 
981  _SEH2_TRY
982  {
983  /* Probe the UNICODE_STRING and the buffer */
984  ProbeForRead(pustrDevice, sizeof(UNICODE_STRING), 1);
985  ProbeForRead(pustrDevice->Buffer, pustrDevice->Length, 1);
986 
987  /* Copy the string */
988  RtlCopyUnicodeString(&ustrDevice, pustrDevice);
989  }
991  {
992  /* Set and return error */
995  }
996  _SEH2_END
997 
998  pustrDevice = &ustrDevice;
999  }
1000 
1001  /* Copy devmode */
1002  if (lpDevMode)
1003  {
1004  _SEH2_TRY
1005  {
1006  /* Probe the size field of the structure */
1007  ProbeForRead(lpDevMode, sizeof(dmLocal.dmSize), 1);
1008 
1009  /* Calculate usable size */
1010  dmLocal.dmSize = min(sizeof(dmLocal), lpDevMode->dmSize);
1011 
1012  /* Probe and copy the full DEVMODE */
1013  ProbeForRead(lpDevMode, dmLocal.dmSize, 1);
1014  RtlCopyMemory(&dmLocal, lpDevMode, dmLocal.dmSize);
1015  }
1017  {
1018  /* Set and return error */
1021  }
1022  _SEH2_END
1023 
1024  /* Check for extra parameters */
1025  if (dmLocal.dmDriverExtra > 0)
1026  {
1027  /* FIXME: TODO */
1028  ERR("lpDevMode->dmDriverExtra is IGNORED!\n");
1029  dmLocal.dmDriverExtra = 0;
1030  }
1031 
1032  /* Use the local structure */
1033  lpDevMode = &dmLocal;
1034  }
1035 
1036  // FIXME: Copy videoparameters
1037 
1038  /* Acquire global USER lock */
1040 
1041  /* Call internal function */
1042  lRet = UserChangeDisplaySettings(pustrDevice, lpDevMode, dwflags, NULL);
1043 
1044  /* Release lock */
1045  UserLeave();
1046 
1047  return lRet;
1048 }
_SEH2_TRY
Definition: create.c:4226
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define DISP_CHANGE_BADFLAGS
Definition: winuser.h:192
WORD dmSize
Definition: wingdi.h:1568
WORD dmDriverExtra
Definition: wingdi.h:1621
_SEH2_END
Definition: create.c:4400
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define CDS_RESET
Definition: winuser.h:187
#define CDS_UPDATEREGISTRY
Definition: winuser.h:181
long LONG
Definition: pedump.c:60
#define DISP_CHANGE_BADPARAM
Definition: winuser.h:193
static _In_ DWORD _Inout_ PDEVMODEA lpDevMode
Definition: dispmode.c:77
#define CDS_GLOBAL
Definition: winuser.h:184
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:249
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define CDS_VIDEOPARAMETERS
Definition: winuser.h:186
WORD dmSize
Definition: wingdi.h:1620
LONG APIENTRY UserChangeDisplaySettings(PUNICODE_STRING pustrDevice, LPDEVMODEW pdm, DWORD flags, LPVOID lParam)
Definition: display.c:716
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
static _In_ DWORD dwflags
Definition: dispmode.c:64
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:37
#define ERR(fmt,...)
Definition: debug.h:110
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:258
#define CCHDEVICENAME
Definition: ddrawi.h:63
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define CDS_NORESET
Definition: winuser.h:189
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
LPARAM lParam
Definition: combotst.c:139
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28

Referenced by ChangeDisplaySettingsExA(), and ChangeDisplaySettingsExW().

◆ NtUserEnumDisplayDevices()

BOOL NTAPI NtUserEnumDisplayDevices ( PUNICODE_STRING  pustrDevice,
DWORD  iDevNum,
PDISPLAY_DEVICEW  pDisplayDevice,
DWORD  dwFlags 
)

Definition at line 366 of file display.c.

371 {
372  UNICODE_STRING ustrDevice;
373  WCHAR awcDevice[CCHDEVICENAME];
374  DISPLAY_DEVICEW dispdev;
376 
377  TRACE("Enter NtUserEnumDisplayDevices(%wZ, %lu)\n",
378  pustrDevice, iDevNum);
379 
380  dispdev.cb = sizeof(dispdev);
381 
382  if (pustrDevice)
383  {
384  /* Initialize destination string */
385  RtlInitEmptyUnicodeString(&ustrDevice, awcDevice, sizeof(awcDevice));
386 
387  _SEH2_TRY
388  {
389  /* Probe the UNICODE_STRING and the buffer */
390  ProbeForRead(pustrDevice, sizeof(UNICODE_STRING), 1);
391  ProbeForRead(pustrDevice->Buffer, pustrDevice->Length, 1);
392 
393  /* Copy the string */
394  RtlCopyUnicodeString(&ustrDevice, pustrDevice);
395  }
397  {
398 // _SEH2_YIELD(return _SEH2_GetExceptionCode());
400  }
401  _SEH2_END
402 
403  if (ustrDevice.Length > 0)
404  pustrDevice = &ustrDevice;
405  else
406  pustrDevice = NULL;
407  }
408 
409  /* If name is given only iDevNum==0 gives results */
410  if (pustrDevice && iDevNum != 0)
411  return FALSE;
412 
413  /* Acquire global USER lock */
414  UserEnterShared();
415 
416  /* Call the internal function */
417  Status = UserEnumDisplayDevices(pustrDevice, iDevNum, &dispdev, dwFlags);
418 
419  /* Release lock */
420  UserLeave();
421 
422  /* On success copy data to caller */
423  if (NT_SUCCESS(Status))
424  {
425  /* Enter SEH */
426  _SEH2_TRY
427  {
428  /* First probe the cb field */
429  ProbeForWrite(&pDisplayDevice->cb, sizeof(DWORD), 1);
430 
431  /* Check the buffer size */
432  if (pDisplayDevice->cb)
433  {
434  /* Probe the output buffer */
435  pDisplayDevice->cb = min(pDisplayDevice->cb, sizeof(dispdev));
436  ProbeForWrite(pDisplayDevice, pDisplayDevice->cb, 1);
437 
438  /* Copy as much as the given buffer allows */
439  RtlCopyMemory(pDisplayDevice, &dispdev, pDisplayDevice->cb);
440  }
441  }
443  {
445  }
446  _SEH2_END
447  }
448 
449  TRACE("Leave NtUserEnumDisplayDevices, Status = 0x%lx\n", Status);
450  /* Return the result */
451 // return Status;
452  return NT_SUCCESS(Status); // FIXME
453 }
_SEH2_TRY
Definition: create.c:4226
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:242
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_END
Definition: create.c:4400
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI UserEnumDisplayDevices(PUNICODE_STRING pustrDevice, DWORD iDevNum, PDISPLAY_DEVICEW pdispdev, DWORD dwFlags)
Definition: display.c:233
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:258
#define CCHDEVICENAME
Definition: ddrawi.h:63
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168

Referenced by EnumDisplayDevicesA(), and EnumDisplayDevicesW().

◆ NtUserEnumDisplaySettings()

NTSTATUS APIENTRY NtUserEnumDisplaySettings ( IN PUNICODE_STRING  pustrDevice,
IN DWORD  iModeNum,
OUT LPDEVMODEW  lpDevMode,
IN DWORD  dwFlags 
)

Definition at line 588 of file display.c.

593 {
594  UNICODE_STRING ustrDeviceUser;
595  UNICODE_STRING ustrDevice;
596  WCHAR awcDevice[CCHDEVICENAME];
598  ULONG cbSize, cbExtra;
599  DEVMODEW dmReg, *pdm;
600 
601  TRACE("Enter NtUserEnumDisplaySettings(%wZ, %lu, %p, 0x%lx)\n",
602  pustrDevice, iModeNum, lpDevMode, dwFlags);
603 
604  _SEH2_TRY
605  {
606  ProbeForRead(lpDevMode, sizeof(DEVMODEW), sizeof(UCHAR));
607 
608  cbSize = lpDevMode->dmSize;
609  cbExtra = lpDevMode->dmDriverExtra;
610 
611  ProbeForWrite(lpDevMode, cbSize + cbExtra, sizeof(UCHAR));
612  }
614  {
616  }
617  _SEH2_END;
618 
619  if (cbSize != sizeof(DEVMODEW))
620  {
622  }
623 
624  if (pustrDevice)
625  {
626  /* Initialize destination string */
627  RtlInitEmptyUnicodeString(&ustrDevice, awcDevice, sizeof(awcDevice));
628 
629  _SEH2_TRY
630  {
631  /* Probe the UNICODE_STRING and the buffer */
632  ustrDeviceUser = ProbeForReadUnicodeString(pustrDevice);
633 
634  if (!ustrDeviceUser.Length || !ustrDeviceUser.Buffer)
636 
637  ProbeForRead(ustrDeviceUser.Buffer,
638  ustrDeviceUser.Length,
639  sizeof(UCHAR));
640 
641  /* Copy the string */
642  RtlCopyUnicodeString(&ustrDevice, &ustrDeviceUser);
643  }
645  {
647  }
648  _SEH2_END;
649 
650  pustrDevice = &ustrDevice;
651  }
652 
653  /* Acquire global USER lock */
654  UserEnterShared();
655 
657  {
658  /* Get the registry settings */
659  Status = UserEnumRegistryDisplaySettings(pustrDevice, &dmReg);
660  pdm = &dmReg;
661  pdm->dmSize = sizeof(DEVMODEW);
662  }
663  else if (iModeNum == ENUM_CURRENT_SETTINGS)
664  {
665  /* Get the current settings */
666  Status = UserEnumCurrentDisplaySettings(pustrDevice, &pdm);
667  }
668  else
669  {
670  /* Get specified settings */
671  Status = UserEnumDisplaySettings(pustrDevice, iModeNum, &pdm, dwFlags);
672  }
673 
674  /* Release lock */
675  UserLeave();
676 
677  /* Did we succeed? */
678  if (NT_SUCCESS(Status))
679  {
680  /* Copy some information back */
681  _SEH2_TRY
682  {
683  /* Output what we got */
684  RtlCopyMemory(lpDevMode, pdm, min(cbSize, pdm->dmSize));
685 
686  /* Output private/extra driver data */
687  if (cbExtra > 0 && pdm->dmDriverExtra > 0)
688  {
689  RtlCopyMemory((PCHAR)lpDevMode + cbSize,
690  (PCHAR)pdm + pdm->dmSize,
691  min(cbExtra, pdm->dmDriverExtra));
692  }
693  }
695  {
697  }
698  _SEH2_END;
699  }
700 
701  return Status;
702 }
_SEH2_TRY
Definition: create.c:4226
signed char * PCHAR
Definition: retypes.h:7
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:242
WORD dmSize
Definition: wingdi.h:1568
WORD dmDriverExtra
Definition: wingdi.h:1569
LONG NTSTATUS
Definition: precomp.h:26
WORD dmDriverExtra
Definition: wingdi.h:1621
#define ExRaiseStatus
Definition: ntoskrnl.h:108
NTSTATUS NTAPI UserEnumRegistryDisplaySettings(IN PUNICODE_STRING pustrDevice, OUT LPDEVMODEW pdm)
Definition: display.c:571
_SEH2_END
Definition: create.c:4400
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define ENUM_CURRENT_SETTINGS
Definition: winuser.h:179
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
static _In_ DWORD iModeNum
Definition: dispmode.c:77
NTSTATUS NTAPI UserEnumCurrentDisplaySettings(PUNICODE_STRING pustrDevice, PDEVMODEW *ppdm)
Definition: display.c:457
static _In_ DWORD _Inout_ PDEVMODEA lpDevMode
Definition: dispmode.c:77
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
WORD dmSize
Definition: wingdi.h:1620
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:258
#define CCHDEVICENAME
Definition: ddrawi.h:63
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define min(a, b)
Definition: monoChain.cc:55
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI UserEnumDisplaySettings(PUNICODE_STRING pustrDevice, DWORD iModeNum, LPDEVMODEW *ppdm, DWORD dwFlags)
Definition: display.c:480
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
struct _devicemodeW DEVMODEW
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ENUM_REGISTRY_SETTINGS
Definition: winuser.h:180

Referenced by EnumDisplaySettingsExA(), and EnumDisplaySettingsExW().

◆ RegReadDisplaySettings()

VOID RegReadDisplaySettings ( HKEY  hkey,
PDEVMODEW  pdm 
)

Definition at line 35 of file display.c.

36 {
37  DWORD dwValue;
38 
39  /* Zero out the structure */
40  RtlZeroMemory(pdm, sizeof(DEVMODEW));
41 
42 /* Helper macro */
43 #define READ(field, str, flag) \
44  if (RegReadDWORD(hkey, L##str, &dwValue)) \
45  { \
46  pdm->field = dwValue; \
47  pdm->dmFields |= flag; \
48  }
49 
50  /* Read all present settings */
51  READ(dmBitsPerPel, "DefaultSettings.BitsPerPel", DM_BITSPERPEL);
52  READ(dmPelsWidth, "DefaultSettings.XResolution", DM_PELSWIDTH);
53  READ(dmPelsHeight, "DefaultSettings.YResolution", DM_PELSHEIGHT);
54  READ(dmDisplayFlags, "DefaultSettings.Flags", DM_DISPLAYFLAGS);
55  READ(dmDisplayFrequency, "DefaultSettings.VRefresh", DM_DISPLAYFREQUENCY);
56  READ(dmPanningWidth, "DefaultSettings.XPanning", DM_PANNINGWIDTH);
57  READ(dmPanningHeight, "DefaultSettings.YPanning", DM_PANNINGHEIGHT);
58  READ(dmDisplayOrientation, "DefaultSettings.Orientation", DM_DISPLAYORIENTATION);
59  READ(dmDisplayFixedOutput, "DefaultSettings.FixedOutput", DM_DISPLAYFIXEDOUTPUT);
60  READ(dmPosition.x, "Attach.RelativeX", DM_POSITION);
61  READ(dmPosition.y, "Attach.RelativeY", DM_POSITION);
62 }
#define READ(field, str, flag)
#define DM_PANNINGWIDTH
Definition: wingdi.h:1277
#define DM_PELSWIDTH
Definition: wingdi.h:1269
#define DM_POSITION
Definition: wingdi.h:1255
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1272
#define DM_PELSHEIGHT
Definition: wingdi.h:1270
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define DM_BITSPERPEL
Definition: wingdi.h:1268
#define DM_DISPLAYORIENTATION
Definition: wingdi.h:1257
#define DM_PANNINGHEIGHT
Definition: wingdi.h:1278
#define DM_DISPLAYFLAGS
Definition: wingdi.h:1271

Referenced by UserEnumRegistryDisplaySettings().

◆ RegWriteDisplaySettings()

VOID RegWriteDisplaySettings ( HKEY  hkey,
PDEVMODEW  pdm 
)

Definition at line 18 of file display.c.

19 {
20  RegWriteDWORD(hkey, L"DefaultSettings.BitsPerPel", pdm->dmBitsPerPel);
21  RegWriteDWORD(hkey, L"DefaultSettings.XResolution", pdm->dmPelsWidth);
22  RegWriteDWORD(hkey, L"DefaultSettings.YResolution", pdm->dmPelsHeight);
23  RegWriteDWORD(hkey, L"DefaultSettings.Flags", pdm->dmDisplayFlags);
24  RegWriteDWORD(hkey, L"DefaultSettings.VRefresh", pdm->dmDisplayFrequency);
25  RegWriteDWORD(hkey, L"DefaultSettings.XPanning", pdm->dmPanningWidth);
26  RegWriteDWORD(hkey, L"DefaultSettings.YPanning", pdm->dmPanningHeight);
27  RegWriteDWORD(hkey, L"DefaultSettings.Orientation", pdm->dmDisplayOrientation);
28  RegWriteDWORD(hkey, L"DefaultSettings.FixedOutput", pdm->dmDisplayFixedOutput);
29  RegWriteDWORD(hkey, L"Attach.RelativeX", pdm->dmPosition.x);
30  RegWriteDWORD(hkey, L"Attach.RelativeY", pdm->dmPosition.y);
31 // RegWriteDWORD(hkey, L"Attach.ToDesktop, pdm->dmBitsPerPel", pdm->);
32 }
DWORD dmDisplayOrientation
Definition: wingdi.h:1636
POINTL dmPosition
Definition: wingdi.h:1635
DWORD dmBitsPerPel
Definition: wingdi.h:1647
LONG y
Definition: windef.h:330
#define L(x)
Definition: ntvdm.h:50
DWORD dmDisplayFixedOutput
Definition: wingdi.h:1637
VOID NTAPI RegWriteDWORD(HKEY hkey, PWSTR pwszValue, DWORD dwData)
Definition: registry.c:140
LONG x
Definition: windef.h:329
DWORD dmPelsWidth
Definition: wingdi.h:1648
DWORD dmDisplayFrequency
Definition: wingdi.h:1654
DWORD dmPelsHeight
Definition: wingdi.h:1649
DWORD dmDisplayFlags
Definition: wingdi.h:1651

Referenced by UserChangeDisplaySettings().

◆ UserChangeDisplaySettings()

LONG APIENTRY UserChangeDisplaySettings ( PUNICODE_STRING  pustrDevice,
LPDEVMODEW  pdm,
DWORD  flags,
LPVOID  lParam 
)

Definition at line 716 of file display.c.

721 {
722  DEVMODEW dm;
723  LONG lResult = DISP_CHANGE_SUCCESSFUL;
724  HKEY hkey;
726  PPDEVOBJ ppdev;
727  WORD OrigBC;
728  //PDESKTOP pdesk;
729  PDEVMODEW newDevMode = NULL;
730 
731  /* If no DEVMODE is given, use registry settings */
732  if (!pdm)
733  {
734  /* Get the registry settings */
735  Status = UserEnumRegistryDisplaySettings(pustrDevice, &dm);
736  if (!NT_SUCCESS(Status))
737  {
738  ERR("Could not load registry settings\n");
739  return DISP_CHANGE_BADPARAM;
740  }
741  }
742  else if (pdm->dmSize < FIELD_OFFSET(DEVMODEW, dmFields))
743  {
744  return DISP_CHANGE_BADMODE; /* This is what WinXP SP3 returns */
745  }
746  else
747  {
748  dm = *pdm;
749  }
750 
751  /* Save original bit count */
752  OrigBC = gpsi->BitCount;
753 
754  /* Check params */
756  {
757  ERR("Devmode doesn't specify the resolution.\n");
758  return DISP_CHANGE_BADMODE;
759  }
760 
761  /* Get the PDEV */
762  ppdev = EngpGetPDEV(pustrDevice);
763  if (!ppdev)
764  {
765  ERR("Failed to get PDEV\n");
766  return DISP_CHANGE_BADPARAM;
767  }
768 
769  /* Fixup values */
770  if (dm.dmBitsPerPel == 0 || !(dm.dmFields & DM_BITSPERPEL))
771  {
772  dm.dmBitsPerPel = ppdev->pdmwDev->dmBitsPerPel;
773  dm.dmFields |= DM_BITSPERPEL;
774  }
775 
776  if ((dm.dmFields & DM_DISPLAYFREQUENCY) && (dm.dmDisplayFrequency == 0))
778 
779  /* Look for the requested DEVMODE */
780  if (!LDEVOBJ_bProbeAndCaptureDevmode(ppdev->pGraphicsDevice, &dm, &newDevMode, FALSE))
781  {
782  ERR("Could not find a matching DEVMODE\n");
783  lResult = DISP_CHANGE_BADMODE;
784  goto leave;
785  }
786  else if (flags & CDS_TEST)
787  {
788  /* It's possible, go ahead! */
789  lResult = DISP_CHANGE_SUCCESSFUL;
790  goto leave;
791  }
792 
793  /* Shall we update the registry? */
795  {
796  /* Open the local or global settings key */
797  Status = UserOpenDisplaySettingsKey(&hkey, pustrDevice, flags & CDS_GLOBAL);
798  if (NT_SUCCESS(Status))
799  {
800  /* Store the settings */
801  RegWriteDisplaySettings(hkey, newDevMode);
802 
803  /* Close the registry key */
804  ZwClose(hkey);
805  }
806  else
807  {
808  ERR("Could not open registry key\n");
809  lResult = DISP_CHANGE_NOTUPDATED;
810  }
811  }
812 
813  /* Check if DEVMODE matches the current mode */
814  if (newDevMode->dmSize == ppdev->pdmwDev->dmSize &&
815  RtlCompareMemory(newDevMode, ppdev->pdmwDev, newDevMode->dmSize) == newDevMode->dmSize &&
816  !(flags & CDS_RESET))
817  {
818  ERR("DEVMODE matches, nothing to do\n");
819  goto leave;
820  }
821 
822  /* Shall we apply the settings? */
823  if (!(flags & CDS_NORESET))
824  {
825  ULONG_PTR ulResult;
826  PVOID pvOldCursor;
827  TEXTMETRICW tmw;
828 
829  /* Remove mouse pointer */
830  pvOldCursor = UserSetCursor(NULL, TRUE);
831 
832  /* Do the mode switch */
833  ulResult = PDEVOBJ_bSwitchMode(ppdev, newDevMode);
834 
835  /* Restore mouse pointer, no hooks called */
836  pvOldCursor = UserSetCursor(pvOldCursor, TRUE);
837  ASSERT(pvOldCursor == NULL);
838 
839  /* Check for success or failure */
840  if (!ulResult)
841  {
842  /* Setting mode failed */
843  ERR("Failed to set mode\n");
844 
845  /* Set the correct return value */
846  if ((flags & CDS_UPDATEREGISTRY) && (lResult != DISP_CHANGE_NOTUPDATED))
847  lResult = DISP_CHANGE_RESTART;
848  else
849  lResult = DISP_CHANGE_FAILED;
850  }
851  else
852  {
853  /* Setting mode succeeded */
854  lResult = DISP_CHANGE_SUCCESSFUL;
856  ppdev->pdmwDev = newDevMode;
857 
859 
860  /* Update the system metrics */
861  InitMetrics();
862 
863  /* Set new size of the monitor */
864  UserUpdateMonitorSize((HDEV)ppdev);
865 
866  /* Update the SERVERINFO */
867  gpsi->dmLogPixels = ppdev->gdiinfo.ulLogPixelsY;
868  gpsi->Planes = ppdev->gdiinfo.cPlanes;
869  gpsi->BitsPixel = ppdev->gdiinfo.cBitsPixel;
870  gpsi->BitCount = gpsi->Planes * gpsi->BitsPixel;
871  gpsi->aiSysMet[SM_CXSCREEN] = ppdev->gdiinfo.ulHorzRes;
872  gpsi->aiSysMet[SM_CYSCREEN] = ppdev->gdiinfo.ulVertRes;
873  if (ppdev->gdiinfo.flRaster & RC_PALETTE)
874  {
875  gpsi->PUSIFlags |= PUSIF_PALETTEDISPLAY;
876  }
877  else
878  {
879  gpsi->PUSIFlags &= ~PUSIF_PALETTEDISPLAY;
880  }
881  // Font is realized and this dc was previously set to internal DC_ATTR.
882  gpsi->cxSysFontChar = IntGetCharDimensions(hSystemBM, &tmw, (DWORD*)&gpsi->cySysFontChar);
883  gpsi->tmSysFont = tmw;
884  }
885 
886  /*
887  * Refresh the display on success and even on failure,
888  * since the display may have been messed up.
889  */
890 
891  /* Remove all cursor clipping */
893 
894  //pdesk = IntGetActiveDesktop();
895  //IntHideDesktop(pdesk);
896 
897  /* Send WM_DISPLAYCHANGE to all toplevel windows */
899  WM_DISPLAYCHANGE,
900  gpsi->BitCount,
901  MAKELONG(gpsi->aiSysMet[SM_CXSCREEN], gpsi->aiSysMet[SM_CYSCREEN]),
902  SMTO_NORMAL,
903  100,
904  &ulResult );
905 
906  ERR("BitCount New %d Orig %d ChkNew %d\n",gpsi->BitCount,OrigBC,ppdev->gdiinfo.cBitsPixel);
907 
908  /* Not full screen and different bit count, send messages */
909  if (!(flags & CDS_FULLSCREEN) &&
910  gpsi->BitCount != OrigBC)
911  {
912  ERR("Detect settings changed.\n");
915  }
916 
917  //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
918 
920  }
921 
922 leave:
923  if (newDevMode && newDevMode != ppdev->pdmwDev)
924  ExFreePoolWithTag(newDevMode, GDITAG_DEVMODE);
925 
926  /* Release the PDEV */
927  PDEVOBJ_vRelease(ppdev);
928 
929  return lResult;
930 }
BOOL NTAPI PDEVOBJ_bSwitchMode(PPDEVOBJ ppdev, PDEVMODEW pdm)
Definition: pdevobj.c:640
#define WM_SYSCOLORCHANGE
Definition: winuser.h:1616
#define GDITAG_DEVMODE
Definition: tags.h:73
NTSTATUS NTAPI UserUpdateMonitorSize(IN HDEV hDev)
Definition: monitor.c:225
#define DISP_CHANGE_RESTART
Definition: winuser.h:191
DWORD dmFields
Definition: wingdi.h:1622
BOOL LDEVOBJ_bProbeAndCaptureDevmode(_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW RequestedMode, _Out_ PDEVMODEW *pSelectedMode, _In_ BOOL bSearchClosestMode)
Definition: ldevobj.c:735
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
GDIINFO gdiinfo
Definition: pdevobj.h:123
#define CDS_FULLSCREEN
Definition: winuser.h:183
LONG NTSTATUS
Definition: precomp.h:26
BOOL FASTCALL UserSendNotifyMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:2037
PSERVERINFO gpsi
Definition: imm.c:17
#define DISP_CHANGE_BADMODE
Definition: winuser.h:195
ULONG ulLogPixelsY
Definition: winddi.h:889
VOID RegWriteDisplaySettings(HKEY hkey, PDEVMODEW pdm)
Definition: display.c:18
NTSTATUS NTAPI UserEnumRegistryDisplaySettings(IN PUNICODE_STRING pustrDevice, OUT LPDEVMODEW pdm)
Definition: display.c:571
ULONG cPlanes
Definition: winddi.h:885
DWORD dmBitsPerPel
Definition: wingdi.h:1647
#define WM_SETTINGCHANGE
Definition: winuser.h:1619
#define SMTO_NORMAL
Definition: winuser.h:1215
#define CDS_RESET
Definition: winuser.h:187
#define DM_PELSWIDTH
Definition: wingdi.h:1269
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define SM_CXSCREEN
Definition: winuser.h:953
#define CDS_UPDATEREGISTRY
Definition: winuser.h:181
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
DWORD FASTCALL IntGetCharDimensions(HDC hdc, PTEXTMETRICW ptm, PDWORD height)
Definition: font.c:329
#define DISP_CHANGE_FAILED
Definition: winuser.h:194
#define DISP_CHANGE_BADPARAM
Definition: winuser.h:193
#define DISP_CHANGE_NOTUPDATED
Definition: winuser.h:196
#define MAKELONG(a, b)
Definition: typedefs.h:249
ULONG ulHorzRes
Definition: winddi.h:882
PDEVMODEW pdmwDev
Definition: pdevobj.h:129
#define CDS_GLOBAL
Definition: winuser.h:184
VOID UserUpdateFullscreen(DWORD flags)
Definition: display.c:705
BOOL APIENTRY UserClipCursor(RECTL *prcl)
Definition: cursoricon.c:700
Status
Definition: gdiplustypes.h:24
#define SM_CYSCREEN
Definition: winuser.h:954
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HDC hSystemBM
Definition: stockobj.c:52
#define RC_PALETTE
Definition: wingdi.h:790
WORD dmSize
Definition: wingdi.h:1620
BOOL NTAPI InitMetrics(VOID)
Definition: metric.c:33
LRESULT FASTCALL co_IntSendMessageTimeout(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, UINT uFlags, UINT uTimeout, ULONG_PTR *uResult)
Definition: message.c:1654
#define DISP_CHANGE_SUCCESSFUL
Definition: winuser.h:190
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
ULONG flRaster
Definition: winddi.h:887
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1272
ULONG cBitsPixel
Definition: winddi.h:884
VOID APIENTRY UserRedrawDesktop(VOID)
Definition: desktop.c:1599
#define ERR(fmt,...)
Definition: debug.h:110
DWORD dmDisplayFrequency
Definition: wingdi.h:1654
#define DM_PELSHEIGHT
Definition: wingdi.h:1270
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
NTSTATUS NTAPI UserOpenDisplaySettingsKey(OUT PHKEY phkey, IN PUNICODE_STRING pustrDevice, IN BOOL bGlobal)
Definition: display.c:540
#define NULL
Definition: types.h:112
#define CDS_NORESET
Definition: winuser.h:189
#define leave
Definition: btrfs_drv.h:138
#define PUSIF_PALETTEDISPLAY
Definition: ntuser.h:972
#define DM_BITSPERPEL
Definition: wingdi.h:1268
ULONG ulVertRes
Definition: winddi.h:883
#define CDS_TEST
Definition: winuser.h:182
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:104
PCURICON_OBJECT FASTCALL UserSetCursor(PCURICON_OBJECT NewCursor, BOOL ForceChange)
Definition: msgqueue.c:93
PGRAPHICS_DEVICE pGraphicsDevice
Definition: pdevobj.h:127
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define HWND_BROADCAST
Definition: winuser.h:1194
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
PPDEVOBJ NTAPI EngpGetPDEV(_In_opt_ PUNICODE_STRING pustrDeviceName)
Definition: pdevobj.c:726

Referenced by NtUserChangeDisplaySettings(), and UserDisplayNotifyShutdown().

◆ UserDisplayNotifyShutdown()

VOID UserDisplayNotifyShutdown ( PPROCESSINFO  ppiCurrent)

Definition at line 933 of file display.c.

935 {
936  if (ppiCurrent == gpFullscreen)
937  {
939  if (gpFullscreen)
940  ERR("Failed to restore display mode!\n");
941  }
942 }
static PPROCESSINFO gpFullscreen
Definition: display.c:13
LONG APIENTRY UserChangeDisplaySettings(PUNICODE_STRING pustrDevice, LPDEVMODEW pdm, DWORD flags, LPVOID lParam)
Definition: display.c:716
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112

Referenced by ExitThreadCallback().

◆ UserEnumCurrentDisplaySettings()

NTSTATUS NTAPI UserEnumCurrentDisplaySettings ( PUNICODE_STRING  pustrDevice,
PDEVMODEW ppdm 
)

Definition at line 457 of file display.c.

460 {
461  PPDEVOBJ ppdev;
462 
463  /* Get the PDEV for the device */
464  ppdev = EngpGetPDEV(pustrDevice);
465  if (!ppdev)
466  {
467  /* No device found */
468  ERR("No PDEV found!\n");
470  }
471 
472  *ppdm = ppdev->pdmwDev;
473  PDEVOBJ_vRelease(ppdev);
474 
475  return STATUS_SUCCESS;
476 }
PDEVMODEW pdmwDev
Definition: pdevobj.h:129
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
#define ERR(fmt,...)
Definition: debug.h:110
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:104
PPDEVOBJ NTAPI EngpGetPDEV(_In_opt_ PUNICODE_STRING pustrDeviceName)
Definition: pdevobj.c:726

Referenced by NtUserEnumDisplaySettings().

◆ UserEnumDisplayDevices()

NTSTATUS NTAPI UserEnumDisplayDevices ( PUNICODE_STRING  pustrDevice,
DWORD  iDevNum,
PDISPLAY_DEVICEW  pdispdev,
DWORD  dwFlags 
)

Definition at line 233 of file display.c.

238 {
239  PGRAPHICS_DEVICE pGraphicsDevice;
240  PDEVICE_OBJECT pdo;
241  PWCHAR pHardwareId;
242  ULONG cbSize, dwLength;
243  HKEY hkey;
245 
246  if (!pustrDevice)
247  {
248  /* Check if some devices have been added since last time */
250  }
251 
252  /* Ask gdi for the GRAPHICS_DEVICE */
253  pGraphicsDevice = EngpFindGraphicsDevice(pustrDevice, iDevNum);
254  if (!pGraphicsDevice)
255  {
256  /* No device found */
257  if (iDevNum == 0)
258  ERR("No GRAPHICS_DEVICE found for '%wZ', iDevNum %lu\n", pustrDevice, iDevNum);
259  else
260  TRACE("No GRAPHICS_DEVICE found for '%wZ', iDevNum %lu\n", pustrDevice, iDevNum);
261  return STATUS_UNSUCCESSFUL;
262  }
263 
264  /* Open the device map registry key */
265  Status = RegOpenKey(KEY_VIDEO, &hkey);
266  if (!NT_SUCCESS(Status))
267  {
268  /* No device found */
269  ERR("Could not open reg key\n");
270  return STATUS_UNSUCCESSFUL;
271  }
272 
273  /* Query the registry path */
274  cbSize = sizeof(pdispdev->DeviceKey);
275  RegQueryValue(hkey,
276  pGraphicsDevice->szNtDeviceName,
277  REG_SZ,
278  pdispdev->DeviceKey,
279  &cbSize);
280 
281  /* Close registry key */
282  ZwClose(hkey);
283 
284  /* Copy device name, device string and StateFlags */
285  RtlStringCbCopyW(pdispdev->DeviceName, sizeof(pdispdev->DeviceName), pGraphicsDevice->szWinDeviceName);
286  RtlStringCbCopyW(pdispdev->DeviceString, sizeof(pdispdev->DeviceString), pGraphicsDevice->pwszDescription);
287  pdispdev->StateFlags = pGraphicsDevice->StateFlags;
288  pdispdev->DeviceID[0] = UNICODE_NULL;
289 
290  /* Fill in DeviceID */
291  if (!pustrDevice)
292  pdo = pGraphicsDevice->PhysDeviceHandle;
293  else
294 #if 0
295  pdo = pGraphicsDevice->pvMonDev[iDevNum].pdo;
296 #else
297  /* FIXME: pvMonDev not initialized, see EngpRegisterGraphicsDevice */
298  pdo = NULL;
299 #endif
300 
301  if (pdo != NULL)
302  {
305  0,
306  NULL,
307  &dwLength);
308 
310  {
311  pHardwareId = ExAllocatePoolWithTag(PagedPool,
312  dwLength,
314  if (!pHardwareId)
315  {
318  }
319 
322  dwLength,
323  pHardwareId,
324  &dwLength);
325 
326  if (!NT_SUCCESS(Status))
327  {
328  ERR("IoGetDeviceProperty() failed with status 0x%08lx\n", Status);
329  }
330  else
331  {
332  /* For video adapters it should be the first Hardware ID
333  * which usually is the longest one and unique enough */
334  RtlStringCbCopyW(pdispdev->DeviceID, sizeof(pdispdev->DeviceID), pHardwareId);
335 
336  if (pustrDevice)
337  {
338  /* For monitors it should be the first Hardware ID,
339  * which we already have obtained above,
340  * concatenated with the unique driver registry key */
341 
342  RtlStringCbCatW(pdispdev->DeviceID, sizeof(pdispdev->DeviceID), L"\\");
343 
344  /* FIXME: DevicePropertyDriverKeyName string should be appended */
345  pHardwareId[0] = UNICODE_NULL;
346  RtlStringCbCatW(pdispdev->DeviceID, sizeof(pdispdev->DeviceID), pHardwareId);
347  }
348 
349  TRACE("Hardware ID: %ls\n", pdispdev->DeviceID);
350  }
351 
353  }
354  else
355  {
356  ERR("IoGetDeviceProperty() failed with status 0x%08lx\n", Status);
357  }
358  }
359 
360  return STATUS_SUCCESS;
361 }
static const PWCHAR KEY_VIDEO
Definition: display.c:15
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
WCHAR szNtDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:59
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
DWORD StateFlags
Definition: pdevobj.h:66
WCHAR DeviceString[128]
Definition: wingdi.h:2819
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
uint16_t * PWCHAR
Definition: typedefs.h:56
NTSTRSAFEAPI RtlStringCbCatW(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:636
WCHAR DeviceName[32]
Definition: wingdi.h:2818
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define L(x)
Definition: ntvdm.h:50
#define UNICODE_NULL
WCHAR DeviceID[128]
Definition: wingdi.h:2821
LPWSTR pwszDescription
Definition: pdevobj.h:72
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1952
PDEVICE_OBJECT PhysDeviceHandle
Definition: pdevobj.h:64
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
static DWORD DWORD * dwLength
Definition: fusion.c:85
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define USERTAG_DISPLAYINFO
Definition: tags.h:225
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PVIDEO_MONITOR_DEVICE pvMonDev
Definition: pdevobj.h:74
DWORD StateFlags
Definition: wingdi.h:2820
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum)
Definition: device.c:469
WCHAR DeviceKey[128]
Definition: wingdi.h:2822
#define ERR(fmt,...)
Definition: debug.h:110
NTSTATUS EngpUpdateGraphicsDeviceList(VOID)
Definition: device.c:36
#define NULL
Definition: types.h:112
#define RegQueryValue
Definition: winreg.h:523
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RegOpenKey
Definition: winreg.h:519
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28
#define REG_SZ
Definition: layer.c:22

Referenced by NtUserEnumDisplayDevices(), and UserOpenDisplaySettingsKey().

◆ UserEnumDisplaySettings()

NTSTATUS NTAPI UserEnumDisplaySettings ( PUNICODE_STRING  pustrDevice,
DWORD  iModeNum,
LPDEVMODEW ppdm,
DWORD  dwFlags 
)

Definition at line 480 of file display.c.

485 {
486  PGRAPHICS_DEVICE pGraphicsDevice;
487  PDEVMODEENTRY pdmentry;
488  ULONG i, iFoundMode;
489  PPDEVOBJ ppdev;
490 
491  TRACE("Enter UserEnumDisplaySettings('%wZ', %lu)\n",
492  pustrDevice, iModeNum);
493 
494  /* Ask GDI for the GRAPHICS_DEVICE */
495  pGraphicsDevice = EngpFindGraphicsDevice(pustrDevice, 0);
496  ppdev = EngpGetPDEV(pustrDevice);
497 
498  if (!pGraphicsDevice || !ppdev)
499  {
500  /* No device found */
501  ERR("No device found!\n");
503  }
504 
505  /* let's politely ask the driver for an updated mode list,
506  just in case there's something new in there (vbox) */
507 
509  PDEVOBJ_vRelease(ppdev);
510 
511  iFoundMode = 0;
512  for (i = 0; i < pGraphicsDevice->cDevModes; i++)
513  {
514  pdmentry = &pGraphicsDevice->pDevModeList[i];
515 
516  /* FIXME: Consider EDS_RAWMODE */
517 #if 0
518  if ((!(dwFlags & EDS_RAWMODE) && (pdmentry->dwFlags & 1)) ||!
519  (dwFlags & EDS_RAWMODE))
520 #endif
521  {
522  /* Is this the one we want? */
523  if (iFoundMode == iModeNum)
524  {
525  *ppdm = pdmentry->pdm;
526  return STATUS_SUCCESS;
527  }
528 
529  /* Increment number of found modes */
530  iFoundMode++;
531  }
532  }
533 
534  /* Nothing was found */
536 }
PDEVMODEENTRY pDevModeList
Definition: pdevobj.h:70
PDEVMODEW pdm
Definition: pdevobj.h:53
static _In_ DWORD iModeNum
Definition: dispmode.c:77
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define TRACE(s)
Definition: solgame.cpp:4
ULONG cDevModes
Definition: pdevobj.h:69
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum)
Definition: device.c:469
#define ERR(fmt,...)
Definition: debug.h:110
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
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI PDEVOBJ_vRefreshModeList(PPDEVOBJ ppdev)
Definition: pdevobj.c:380
DWORD dwFlags
Definition: pdevobj.h:52
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:104
PPDEVOBJ NTAPI EngpGetPDEV(_In_opt_ PUNICODE_STRING pustrDeviceName)
Definition: pdevobj.c:726

Referenced by NtUserEnumDisplaySettings().

◆ UserEnumRegistryDisplaySettings()

NTSTATUS NTAPI UserEnumRegistryDisplaySettings ( IN PUNICODE_STRING  pustrDevice,
OUT LPDEVMODEW  pdm 
)

Definition at line 571 of file display.c.

574 {
575  HKEY hkey;
576  NTSTATUS Status = UserOpenDisplaySettingsKey(&hkey, pustrDevice, 0);
577  if(NT_SUCCESS(Status))
578  {
579  RegReadDisplaySettings(hkey, pdm);
580  ZwClose(hkey);
581  return STATUS_SUCCESS;
582  }
583  return Status;
584 }
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
VOID RegReadDisplaySettings(HKEY hkey, PDEVMODEW pdm)
Definition: display.c:35
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI UserOpenDisplaySettingsKey(OUT PHKEY phkey, IN PUNICODE_STRING pustrDevice, IN BOOL bGlobal)
Definition: display.c:540
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by NtUserEnumDisplaySettings(), and UserChangeDisplaySettings().

◆ UserOpenDisplaySettingsKey()

NTSTATUS NTAPI UserOpenDisplaySettingsKey ( OUT PHKEY  phkey,
IN PUNICODE_STRING  pustrDevice,
IN BOOL  bGlobal 
)

Definition at line 540 of file display.c.

544 {
545  HKEY hkey;
546  DISPLAY_DEVICEW dispdev;
548 
549  /* Get device info */
550  Status = UserEnumDisplayDevices(pustrDevice, 0, &dispdev, 0);
551  if (!NT_SUCCESS(Status))
552  return Status;
553 
554  if (bGlobal)
555  {
556  // FIXME: Need to fix the registry key somehow
557  }
558 
559  /* Open the registry key */
560  Status = RegOpenKey(dispdev.DeviceKey, &hkey);
561  if (!NT_SUCCESS(Status))
562  return Status;
563 
564  *phkey = hkey;
565 
566  return Status;
567 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI UserEnumDisplayDevices(PUNICODE_STRING pustrDevice, DWORD iDevNum, PDISPLAY_DEVICEW pdispdev, DWORD dwFlags)
Definition: display.c:233
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
WCHAR DeviceKey[128]
Definition: wingdi.h:2822
#define RegOpenKey
Definition: winreg.h:519

Referenced by UserChangeDisplaySettings(), and UserEnumRegistryDisplaySettings().

◆ UserRefreshDisplay()

VOID UserRefreshDisplay ( IN PPDEVOBJ  ppdev)

Definition at line 193 of file display.c.

194 {
195  ULONG_PTR ulResult;
196  // PVOID pvOldCursor;
197 
198  // TODO: Re-enable the cursor reset code once this function becomes called
199  // from within a Win32 thread... Indeed UserSetCursor() requires this, but
200  // at the moment this function is directly called from a separate thread
201  // from within videoprt, instead of by a separate win32k system thread.
202 
203  if (!ppdev)
204  return;
205 
206  PDEVOBJ_vReference(ppdev);
207 
208  /* Remove mouse pointer */
209  // pvOldCursor = UserSetCursor(NULL, TRUE);
210 
211  /* Do the mode switch -- Use the actual same current mode */
212  ulResult = PDEVOBJ_bSwitchMode(ppdev, ppdev->pdmwDev);
213  ASSERT(ulResult);
214 
215  /* Restore mouse pointer, no hooks called */
216  // pvOldCursor = UserSetCursor(pvOldCursor, TRUE);
217  // ASSERT(pvOldCursor == NULL);
218 
219  /* Update the system metrics */
220  InitMetrics();
221 
222  /* Set new size of the monitor */
223  // UserUpdateMonitorSize((HDEV)ppdev);
224 
225  //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
227 
228  PDEVOBJ_vRelease(ppdev);
229 }
BOOL NTAPI PDEVOBJ_bSwitchMode(PPDEVOBJ ppdev, PDEVMODEW pdm)
Definition: pdevobj.c:640
FORCEINLINE VOID PDEVOBJ_vReference(_In_ PPDEVOBJ ppdev)
Definition: pdevobj.h:161
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ASSERT(a)
Definition: mode.c:44
BOOL NTAPI InitMetrics(VOID)
Definition: metric.c:33
VOID APIENTRY UserRedrawDesktop(VOID)
Definition: desktop.c:1599
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:104

Referenced by VideoPortCallout().

◆ UserUpdateFullscreen()

VOID UserUpdateFullscreen ( DWORD  flags)

Definition at line 705 of file display.c.

707 {
708  if (flags & CDS_FULLSCREEN)
710  else
711  gpFullscreen = NULL;
712 }
#define CDS_FULLSCREEN
Definition: winuser.h:183
PPROCESSINFO ppi
Definition: win32.h:84
static PPROCESSINFO gpFullscreen
Definition: display.c:13
PTHREADINFO gptiCurrent
Definition: ntuser.c:15
GLbitfield flags
Definition: glext.h:7161
#define NULL
Definition: types.h:112

Referenced by UserChangeDisplaySettings().

Variable Documentation

◆ gbBaseVideo

BOOL gbBaseVideo = FALSE

Definition at line 12 of file display.c.

Referenced by InitVideo().

◆ gpFullscreen

PPROCESSINFO gpFullscreen = NULL
static

Definition at line 13 of file display.c.

Referenced by UserDisplayNotifyShutdown(), and UserUpdateFullscreen().

◆ KEY_VIDEO

const PWCHAR KEY_VIDEO = L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO"
static

Definition at line 15 of file display.c.

Referenced by EngpGetRegistryHandleFromDeviceMap(), and UserEnumDisplayDevices().