ReactOS  0.4.15-dev-1184-g23e04ae
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; \
}
const WCHAR * str
BOOL NTAPI RegReadDWORD(HKEY hkey, PWSTR pwszValue, PDWORD pdwData)
Definition: registry.c:150
static const WCHAR L[]
Definition: oid.c:1250
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  DEVMODEW dmDefault;
77  DWORD dwVga;
78 
79  TRACE("InitDisplayDriver(%S, %S);\n",
80  pwszDeviceName, pwszRegKey);
81 
82  /* Open the driver's registry key */
83  Status = RegOpenKey(pwszRegKey, &hkey);
84  if (!NT_SUCCESS(Status))
85  {
86  ERR("Failed to open registry key: %ls\n", pwszRegKey);
87  return NULL;
88  }
89 
90  /* Query the diplay drivers */
91  cbSize = sizeof(awcBuffer) - 10;
92  Status = RegQueryValue(hkey,
93  L"InstalledDisplayDrivers",
95  awcBuffer,
96  &cbSize);
97  if (!NT_SUCCESS(Status))
98  {
99  ERR("Didn't find 'InstalledDisplayDrivers', status = 0x%lx\n", Status);
100  ZwClose(hkey);
101  return NULL;
102  }
103 
104  /* Initialize the UNICODE_STRING */
105  ustrDisplayDrivers.Buffer = awcBuffer;
106  ustrDisplayDrivers.MaximumLength = (USHORT)cbSize;
107  ustrDisplayDrivers.Length = (USHORT)cbSize;
108 
109  /* Set Buffer for description and size of remaining buffer */
110  ustrDescription.Buffer = awcBuffer + (cbSize / sizeof(WCHAR));
111  cbSize = sizeof(awcBuffer) - cbSize;
112 
113  /* Query the device string */
114  Status = RegQueryValue(hkey,
115  L"Device Description",
116  REG_SZ,
117  ustrDescription.Buffer,
118  &cbSize);
119  if (NT_SUCCESS(Status))
120  {
121  ustrDescription.MaximumLength = (USHORT)cbSize;
122  ustrDescription.Length = (USHORT)cbSize;
123  }
124  else
125  {
126  RtlInitUnicodeString(&ustrDescription, L"<unknown>");
127  }
128 
129  /* Query the default settings */
130  RegReadDisplaySettings(hkey, &dmDefault);
131 
132  /* Query if this is a VGA compatible driver */
133  cbSize = sizeof(DWORD);
134  Status = RegQueryValue(hkey, L"VgaCompatible", REG_DWORD, &dwVga, &cbSize);
135  if (!NT_SUCCESS(Status)) dwVga = 0;
136 
137  /* Close the registry key */
138  ZwClose(hkey);
139 
140  /* Register the device with GDI */
141  RtlInitUnicodeString(&ustrDeviceName, pwszDeviceName);
142  pGraphicsDevice = EngpRegisterGraphicsDevice(&ustrDeviceName,
143  &ustrDisplayDrivers,
144  &ustrDescription,
145  &dmDefault);
146  if (pGraphicsDevice && dwVga)
147  {
148  pGraphicsDevice->StateFlags |= DISPLAY_DEVICE_VGA_COMPATIBLE;
149  }
150 
151  return pGraphicsDevice;
152 }
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
PGRAPHICS_DEVICE NTAPI EngpRegisterGraphicsDevice(_In_ PUNICODE_STRING pustrDeviceName, _In_ PUNICODE_STRING pustrDiplayDrivers, _In_ PUNICODE_STRING pustrDescription, _In_ PDEVMODEW pdmDefault)
Definition: device.c:227
#define REG_MULTI_SZ
Definition: nt_native.h:1501
smooth NULL
Definition: ftsmooth.c:416
VOID RegReadDisplaySettings(HKEY hkey, PDEVMODEW pdm)
Definition: display.c:35
#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
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
_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 DISPLAY_DEVICE_VGA_COMPATIBLE
Definition: wingdi.h:1399
#define RegQueryValue
Definition: winreg.h:523
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RegOpenKey
Definition: winreg.h:519
#define REG_DWORD
Definition: sdbapi.c:596
#define REG_SZ
Definition: layer.c:22

Referenced by InitVideo().

◆ InitVideo()

NTSTATUS NTAPI InitVideo ( VOID  )

Definition at line 156 of file display.c.

157 {
158  ULONG iDevNum, iVGACompatible = -1, ulMaxObjectNumber = 0;
159  WCHAR awcDeviceName[20];
160  WCHAR awcBuffer[256];
162  PGRAPHICS_DEVICE pGraphicsDevice;
163  ULONG cbValue;
164  HKEY hkey;
165 
166  TRACE("----------------------------- InitVideo() -------------------------------\n");
167 
168  /* Check if VGA mode is requested, by finding the special volatile key created by VIDEOPRT */
169  Status = RegOpenKey(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\GraphicsDrivers\\BaseVideo", &hkey);
170  if (NT_SUCCESS(Status))
171  ZwClose(hkey);
173  if (gbBaseVideo)
174  ERR("VGA mode requested.\n");
175 
176  /* Open the key for the adapters */
177  Status = RegOpenKey(KEY_VIDEO, &hkey);
178  if (!NT_SUCCESS(Status))
179  {
180  ERR("Could not open HARDWARE\\DEVICEMAP\\VIDEO registry key:0x%lx\n", Status);
181  return Status;
182  }
183 
184  /* Read the name of the VGA adapter */
185  cbValue = sizeof(awcDeviceName);
186  Status = RegQueryValue(hkey, L"VgaCompatible", REG_SZ, awcDeviceName, &cbValue);
187  if (NT_SUCCESS(Status))
188  {
189  iVGACompatible = _wtoi(&awcDeviceName[sizeof("\\Device\\Video")-1]);
190  ERR("VGA adapter = %lu\n", iVGACompatible);
191  }
192 
193  /* Get the maximum mumber of adapters */
194  if (!RegReadDWORD(hkey, L"MaxObjectNumber", &ulMaxObjectNumber))
195  {
196  ERR("Could not read MaxObjectNumber, defaulting to 0.\n");
197  }
198 
199  TRACE("Found %lu devices\n", ulMaxObjectNumber + 1);
200 
201  /* Loop through all adapters */
202  for (iDevNum = 0; iDevNum <= ulMaxObjectNumber; iDevNum++)
203  {
204  /* Create the adapter's key name */
205  swprintf(awcDeviceName, L"\\Device\\Video%lu", iDevNum);
206 
207  /* Read the reg key name */
208  cbValue = sizeof(awcBuffer);
209  Status = RegQueryValue(hkey, awcDeviceName, REG_SZ, awcBuffer, &cbValue);
210  if (!NT_SUCCESS(Status))
211  {
212  ERR("failed to query the registry path:0x%lx\n", Status);
213  continue;
214  }
215 
216  /* Initialize the driver for this device */
217  pGraphicsDevice = InitDisplayDriver(awcDeviceName, awcBuffer);
218  if (!pGraphicsDevice) continue;
219 
220  /* Check if this is a VGA compatible adapter */
221  if (pGraphicsDevice->StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE)
222  {
223  /* Save this as the VGA adapter */
224  if (!gpVgaGraphicsDevice)
225  gpVgaGraphicsDevice = pGraphicsDevice;
226  TRACE("gpVgaGraphicsDevice = %p\n", gpVgaGraphicsDevice);
227  }
228  else
229  {
230  /* Set the first one as primary device */
232  gpPrimaryGraphicsDevice = pGraphicsDevice;
233  TRACE("gpPrimaryGraphicsDevice = %p\n", gpPrimaryGraphicsDevice);
234  }
235  }
236 
237  /* Close the device map registry key */
238  ZwClose(hkey);
239 
240  /* Was VGA mode requested? */
241  if (gbBaseVideo)
242  {
243  /* Check if we found a VGA compatible device */
245  {
246  /* Set the VgaAdapter as primary */
248  // FIXME: DEVMODE
249  }
250  else
251  {
252  ERR("Could not find VGA compatible driver. Trying normal.\n");
253  }
254  }
255 
256  /* Check if we had any success */
258  {
259  /* Check if there is a VGA device we skipped */
261  {
262  /* There is, use the VGA device */
264  }
265  else
266  {
267  ERR("No usable display driver was found.\n");
268  return STATUS_UNSUCCESSFUL;
269  }
270  }
271 
272  InitSysParams();
273 
274  return STATUS_SUCCESS;
275 }
static const PWCHAR KEY_VIDEO
Definition: display.c:15
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
DWORD StateFlags
Definition: pdevobj.h:66
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
LONG NTSTATUS
Definition: precomp.h:26
PGRAPHICS_DEVICE gpVgaGraphicsDevice
Definition: device.c:16
PGRAPHICS_DEVICE NTAPI InitDisplayDriver(IN PWSTR pwszDeviceName, IN PWSTR pwszRegKey)
Definition: display.c:66
PGRAPHICS_DEVICE gpPrimaryGraphicsDevice
Definition: device.c:15
BOOL InitSysParams(VOID)
Definition: sysparams.c:348
BOOL gbBaseVideo
Definition: display.c:12
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
BOOL NTAPI RegReadDWORD(HKEY hkey, PWSTR pwszValue, PDWORD pdwData)
Definition: registry.c:150
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:110
#define DISPLAY_DEVICE_VGA_COMPATIBLE
Definition: wingdi.h:1399
#define RegQueryValue
Definition: winreg.h:523
unsigned int ULONG
Definition: retypes.h:1
#define RegOpenKey
Definition: winreg.h:519
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define REG_SZ
Definition: layer.c:22

Referenced by UserInitialize().

◆ NtUserChangeDisplaySettings()

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

Definition at line 944 of file display.c.

949 {
950  WCHAR awcDevice[CCHDEVICENAME];
951  UNICODE_STRING ustrDevice;
952  DEVMODEW dmLocal;
953  LONG lRet;
954 
955  /* Check arguments */
956  if ((dwflags != CDS_VIDEOPARAMETERS) && (lParam != NULL))
957  {
959  return DISP_CHANGE_BADPARAM;
960  }
961 
962  /* Check flags */
964  {
965  return DISP_CHANGE_BADFLAGS;
966  }
967 
968  if ((dwflags & CDS_RESET) && (dwflags & CDS_NORESET))
969  {
970  return DISP_CHANGE_BADFLAGS;
971  }
972 
973  /* Copy the device name */
974  if (pustrDevice)
975  {
976  /* Initialize destination string */
977  RtlInitEmptyUnicodeString(&ustrDevice, awcDevice, sizeof(awcDevice));
978 
979  _SEH2_TRY
980  {
981  /* Probe the UNICODE_STRING and the buffer */
982  ProbeForRead(pustrDevice, sizeof(UNICODE_STRING), 1);
983  ProbeForRead(pustrDevice->Buffer, pustrDevice->Length, 1);
984 
985  /* Copy the string */
986  RtlCopyUnicodeString(&ustrDevice, pustrDevice);
987  }
989  {
990  /* Set and return error */
993  }
994  _SEH2_END
995 
996  pustrDevice = &ustrDevice;
997  }
998 
999  /* Copy devmode */
1000  if (lpDevMode)
1001  {
1002  _SEH2_TRY
1003  {
1004  /* Probe the size field of the structure */
1005  ProbeForRead(lpDevMode, sizeof(dmLocal.dmSize), 1);
1006 
1007  /* Calculate usable size */
1008  dmLocal.dmSize = min(sizeof(dmLocal), lpDevMode->dmSize);
1009 
1010  /* Probe and copy the full DEVMODE */
1011  ProbeForRead(lpDevMode, dmLocal.dmSize, 1);
1012  RtlCopyMemory(&dmLocal, lpDevMode, dmLocal.dmSize);
1013  }
1015  {
1016  /* Set and return error */
1019  }
1020  _SEH2_END
1021 
1022  /* Check for extra parameters */
1023  if (dmLocal.dmDriverExtra > 0)
1024  {
1025  /* FIXME: TODO */
1026  ERR("lpDevMode->dmDriverExtra is IGNORED!\n");
1027  dmLocal.dmDriverExtra = 0;
1028  }
1029 
1030  /* Use the local structure */
1031  lpDevMode = &dmLocal;
1032  }
1033 
1034  // FIXME: Copy videoparameters
1035 
1036  /* Acquire global USER lock */
1038 
1039  /* Call internal function */
1040  lRet = UserChangeDisplaySettings(pustrDevice, lpDevMode, dwflags, NULL);
1041 
1042  /* Release lock */
1043  UserLeave();
1044 
1045  return lRet;
1046 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define DISP_CHANGE_BADFLAGS
Definition: winuser.h:192
WORD dmSize
Definition: wingdi.h:1567
WORD dmDriverExtra
Definition: wingdi.h:1620
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
_SEH2_TRY
Definition: create.c:4226
#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
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
static _In_ DWORD _Inout_ PDEVMODEA lpDevMode
Definition: dispmode.c:77
#define CDS_GLOBAL
Definition: winuser.h:184
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CDS_VIDEOPARAMETERS
Definition: winuser.h:186
WORD dmSize
Definition: wingdi.h:1619
LONG APIENTRY UserChangeDisplaySettings(PUNICODE_STRING pustrDevice, LPDEVMODEW pdm, DWORD flags, LPVOID lParam)
Definition: display.c:721
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:36
#define ERR(fmt,...)
Definition: debug.h:110
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
_SEH2_END
Definition: create.c:4400
#define CCHDEVICENAME
Definition: ddrawi.h:63
#define min(a, b)
Definition: monoChain.cc:55
#define CDS_NORESET
Definition: winuser.h:189
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
LPARAM lParam
Definition: combotst.c:139
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27

Referenced by ChangeDisplaySettingsExA(), and ChangeDisplaySettingsExW().

◆ NtUserEnumDisplayDevices()

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

Definition at line 371 of file display.c.

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

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 593 of file display.c.

598 {
599  UNICODE_STRING ustrDeviceUser;
600  UNICODE_STRING ustrDevice;
601  WCHAR awcDevice[CCHDEVICENAME];
603  ULONG cbSize, cbExtra;
604  DEVMODEW dmReg, *pdm;
605 
606  TRACE("Enter NtUserEnumDisplaySettings(%wZ, %lu, %p, 0x%lx)\n",
607  pustrDevice, iModeNum, lpDevMode, dwFlags);
608 
609  _SEH2_TRY
610  {
611  ProbeForRead(lpDevMode, sizeof(DEVMODEW), sizeof(UCHAR));
612 
613  cbSize = lpDevMode->dmSize;
614  cbExtra = lpDevMode->dmDriverExtra;
615 
616  ProbeForWrite(lpDevMode, cbSize + cbExtra, sizeof(UCHAR));
617  }
619  {
621  }
622  _SEH2_END;
623 
624  if (cbSize != sizeof(DEVMODEW))
625  {
627  }
628 
629  if (pustrDevice)
630  {
631  /* Initialize destination string */
632  RtlInitEmptyUnicodeString(&ustrDevice, awcDevice, sizeof(awcDevice));
633 
634  _SEH2_TRY
635  {
636  /* Probe the UNICODE_STRING and the buffer */
637  ustrDeviceUser = ProbeForReadUnicodeString(pustrDevice);
638 
639  if (!ustrDeviceUser.Length || !ustrDeviceUser.Buffer)
641 
642  ProbeForRead(ustrDeviceUser.Buffer,
643  ustrDeviceUser.Length,
644  sizeof(UCHAR));
645 
646  /* Copy the string */
647  RtlCopyUnicodeString(&ustrDevice, &ustrDeviceUser);
648  }
650  {
652  }
653  _SEH2_END;
654 
655  pustrDevice = &ustrDevice;
656  }
657 
658  /* Acquire global USER lock */
659  UserEnterShared();
660 
662  {
663  /* Get the registry settings */
664  Status = UserEnumRegistryDisplaySettings(pustrDevice, &dmReg);
665  pdm = &dmReg;
666  pdm->dmSize = sizeof(DEVMODEW);
667  }
668  else if (iModeNum == ENUM_CURRENT_SETTINGS)
669  {
670  /* Get the current settings */
671  Status = UserEnumCurrentDisplaySettings(pustrDevice, &pdm);
672  }
673  else
674  {
675  /* Get specified settings */
676  Status = UserEnumDisplaySettings(pustrDevice, iModeNum, &pdm, dwFlags);
677  }
678 
679  /* Release lock */
680  UserLeave();
681 
682  /* Did we succeed? */
683  if (NT_SUCCESS(Status))
684  {
685  /* Copy some information back */
686  _SEH2_TRY
687  {
688  /* Output what we got */
689  RtlCopyMemory(lpDevMode, pdm, min(cbSize, pdm->dmSize));
690 
691  /* Output private/extra driver data */
692  if (cbExtra > 0 && pdm->dmDriverExtra > 0)
693  {
694  RtlCopyMemory((PCHAR)lpDevMode + cbSize,
695  (PCHAR)pdm + pdm->dmSize,
696  min(cbExtra, pdm->dmDriverExtra));
697  }
698  }
700  {
702  }
703  _SEH2_END;
704  }
705 
706  return Status;
707 }
signed char * PCHAR
Definition: retypes.h:7
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:241
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
WORD dmSize
Definition: wingdi.h:1567
WORD dmDriverExtra
Definition: wingdi.h:1568
LONG NTSTATUS
Definition: precomp.h:26
WORD dmDriverExtra
Definition: wingdi.h:1620
#define ExRaiseStatus
Definition: ntoskrnl.h:96
NTSTATUS NTAPI UserEnumRegistryDisplaySettings(IN PUNICODE_STRING pustrDevice, OUT LPDEVMODEW pdm)
Definition: display.c:576
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
_SEH2_TRY
Definition: create.c:4226
static _In_ DWORD iModeNum
Definition: dispmode.c:77
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSTATUS NTAPI UserEnumCurrentDisplaySettings(PUNICODE_STRING pustrDevice, PDEVMODEW *ppdm)
Definition: display.c:462
static _In_ DWORD _Inout_ PDEVMODEA lpDevMode
Definition: dispmode.c:77
#define TRACE(s)
Definition: solgame.cpp:4
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
WORD dmSize
Definition: wingdi.h:1619
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
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:255
_SEH2_END
Definition: create.c:4400
#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:485
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
struct _devicemodeW DEVMODEW
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#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:1276
#define DM_PELSWIDTH
Definition: wingdi.h:1268
#define DM_POSITION
Definition: wingdi.h:1254
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1271
#define DM_PELSHEIGHT
Definition: wingdi.h:1269
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define DM_BITSPERPEL
Definition: wingdi.h:1267
#define DM_DISPLAYORIENTATION
Definition: wingdi.h:1256
#define DM_PANNINGHEIGHT
Definition: wingdi.h:1277
#define DM_DISPLAYFLAGS
Definition: wingdi.h:1270

Referenced by InitDisplayDriver(), and 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:1635
POINTL dmPosition
Definition: wingdi.h:1634
DWORD dmBitsPerPel
Definition: wingdi.h:1646
LONG y
Definition: windef.h:330
DWORD dmDisplayFixedOutput
Definition: wingdi.h:1636
VOID NTAPI RegWriteDWORD(HKEY hkey, PWSTR pwszValue, DWORD dwData)
Definition: registry.c:140
LONG x
Definition: windef.h:329
DWORD dmPelsWidth
Definition: wingdi.h:1647
static const WCHAR L[]
Definition: oid.c:1250
DWORD dmDisplayFrequency
Definition: wingdi.h:1653
DWORD dmPelsHeight
Definition: wingdi.h:1648
DWORD dmDisplayFlags
Definition: wingdi.h:1650

Referenced by UserChangeDisplaySettings().

◆ UserChangeDisplaySettings()

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

Definition at line 721 of file display.c.

726 {
727  DEVMODEW dm;
728  LONG lResult = DISP_CHANGE_SUCCESSFUL;
729  HKEY hkey;
731  PPDEVOBJ ppdev;
732  WORD OrigBC;
733  //PDESKTOP pdesk;
734 
735  /* If no DEVMODE is given, use registry settings */
736  if (!pdm)
737  {
738  /* Get the registry settings */
739  Status = UserEnumRegistryDisplaySettings(pustrDevice, &dm);
740  if (!NT_SUCCESS(Status))
741  {
742  ERR("Could not load registry settings\n");
743  return DISP_CHANGE_BADPARAM;
744  }
745  }
746  else if (pdm->dmSize < FIELD_OFFSET(DEVMODEW, dmFields))
747  {
748  return DISP_CHANGE_BADMODE; /* This is what WinXP SP3 returns */
749  }
750  else
751  {
752  dm = *pdm;
753  }
754 
755  /* Save original bit count */
756  OrigBC = gpsi->BitCount;
757 
758  /* Check params */
760  {
761  ERR("Devmode doesn't specify the resolution.\n");
762  return DISP_CHANGE_BADMODE;
763  }
764 
765  /* Get the PDEV */
766  ppdev = EngpGetPDEV(pustrDevice);
767  if (!ppdev)
768  {
769  ERR("Failed to get PDEV\n");
770  return DISP_CHANGE_BADPARAM;
771  }
772 
773  /* Fixup values */
774  if (dm.dmBitsPerPel == 0 || !(dm.dmFields & DM_BITSPERPEL))
775  {
776  dm.dmBitsPerPel = ppdev->pdmwDev->dmBitsPerPel;
777  dm.dmFields |= DM_BITSPERPEL;
778  }
779 
780  if ((dm.dmFields & DM_DISPLAYFREQUENCY) && (dm.dmDisplayFrequency == 0))
782 
783  /* Look for the requested DEVMODE */
784  pdm = PDEVOBJ_pdmMatchDevMode(ppdev, &dm);
785  if (!pdm)
786  {
787  ERR("Could not find a matching DEVMODE\n");
788  lResult = DISP_CHANGE_BADMODE;
789  goto leave;
790  }
791  else if (flags & CDS_TEST)
792  {
793  /* It's possible, go ahead! */
794  lResult = DISP_CHANGE_SUCCESSFUL;
795  goto leave;
796  }
797 
798  /* Shall we update the registry? */
800  {
801  /* Open the local or global settings key */
802  Status = UserOpenDisplaySettingsKey(&hkey, pustrDevice, flags & CDS_GLOBAL);
803  if (NT_SUCCESS(Status))
804  {
805  /* Store the settings */
806  RegWriteDisplaySettings(hkey, pdm);
807 
808  /* Close the registry key */
809  ZwClose(hkey);
810  }
811  else
812  {
813  ERR("Could not open registry key\n");
814  lResult = DISP_CHANGE_NOTUPDATED;
815  }
816  }
817 
818  /* Check if DEVMODE matches the current mode */
819  if (pdm == ppdev->pdmwDev && !(flags & CDS_RESET))
820  {
821  ERR("DEVMODE matches, nothing to do\n");
822  goto leave;
823  }
824 
825  /* Shall we apply the settings? */
826  if (!(flags & CDS_NORESET))
827  {
828  ULONG_PTR ulResult;
829  PVOID pvOldCursor;
830  TEXTMETRICW tmw;
831 
832  /* Remove mouse pointer */
833  pvOldCursor = UserSetCursor(NULL, TRUE);
834 
835  /* Do the mode switch */
836  ulResult = PDEVOBJ_bSwitchMode(ppdev, pdm);
837 
838  /* Restore mouse pointer, no hooks called */
839  pvOldCursor = UserSetCursor(pvOldCursor, TRUE);
840  ASSERT(pvOldCursor == NULL);
841 
842  /* Check for success or failure */
843  if (!ulResult)
844  {
845  /* Setting mode failed */
846  ERR("Failed to set mode\n");
847 
848  /* Set the correct return value */
849  if ((flags & CDS_UPDATEREGISTRY) && (lResult != DISP_CHANGE_NOTUPDATED))
850  lResult = DISP_CHANGE_RESTART;
851  else
852  lResult = DISP_CHANGE_FAILED;
853  }
854  else
855  {
856  /* Setting mode succeeded */
857  lResult = DISP_CHANGE_SUCCESSFUL;
858 
860 
861  /* Update the system metrics */
862  InitMetrics();
863 
864  /* Set new size of the monitor */
865  UserUpdateMonitorSize((HDEV)ppdev);
866 
867  /* Update the SERVERINFO */
868  gpsi->dmLogPixels = ppdev->gdiinfo.ulLogPixelsY;
869  gpsi->Planes = ppdev->gdiinfo.cPlanes;
870  gpsi->BitsPixel = ppdev->gdiinfo.cBitsPixel;
871  gpsi->BitCount = gpsi->Planes * gpsi->BitsPixel;
872  gpsi->aiSysMet[SM_CXSCREEN] = ppdev->gdiinfo.ulHorzRes;
873  gpsi->aiSysMet[SM_CYSCREEN] = ppdev->gdiinfo.ulVertRes;
874  if (ppdev->gdiinfo.flRaster & RC_PALETTE)
875  {
876  gpsi->PUSIFlags |= PUSIF_PALETTEDISPLAY;
877  }
878  else
879  {
880  gpsi->PUSIFlags &= ~PUSIF_PALETTEDISPLAY;
881  }
882  // Font is realized and this dc was previously set to internal DC_ATTR.
883  gpsi->cxSysFontChar = IntGetCharDimensions(hSystemBM, &tmw, (DWORD*)&gpsi->cySysFontChar);
884  gpsi->tmSysFont = tmw;
885  }
886 
887  /*
888  * Refresh the display on success and even on failure,
889  * since the display may have been messed up.
890  */
891 
892  /* Remove all cursor clipping */
894 
895  //pdesk = IntGetActiveDesktop();
896  //IntHideDesktop(pdesk);
897 
898  /* Send WM_DISPLAYCHANGE to all toplevel windows */
900  WM_DISPLAYCHANGE,
901  gpsi->BitCount,
902  MAKELONG(gpsi->aiSysMet[SM_CXSCREEN], gpsi->aiSysMet[SM_CYSCREEN]),
903  SMTO_NORMAL,
904  100,
905  &ulResult );
906 
907  ERR("BitCount New %d Orig %d ChkNew %d\n",gpsi->BitCount,OrigBC,ppdev->gdiinfo.cBitsPixel);
908 
909  /* Not full screen and different bit count, send messages */
910  if (!(flags & CDS_FULLSCREEN) &&
911  gpsi->BitCount != OrigBC)
912  {
913  ERR("Detect settings changed.\n");
916  }
917 
918  //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
919 
921  }
922 
923 leave:
924  /* Release the PDEV */
925  PDEVOBJ_vRelease(ppdev);
926 
927  return lResult;
928 }
BOOL NTAPI PDEVOBJ_bSwitchMode(PPDEVOBJ ppdev, PDEVMODEW pdm)
Definition: pdevobj.c:509
#define WM_SYSCOLORCHANGE
Definition: winuser.h:1608
NTSTATUS NTAPI UserUpdateMonitorSize(IN HDEV hDev)
Definition: monitor.c:225
#define DISP_CHANGE_RESTART
Definition: winuser.h:191
DWORD dmFields
Definition: wingdi.h:1621
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
GDIINFO gdiinfo
Definition: pdevobj.h:124
#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
#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:576
ULONG cPlanes
Definition: winddi.h:885
DWORD dmBitsPerPel
Definition: wingdi.h:1646
PSERVERINFO gpsi
Definition: main.c:27
#define WM_SETTINGCHANGE
Definition: winuser.h:1611
#define SMTO_NORMAL
Definition: winuser.h:1211
#define CDS_RESET
Definition: winuser.h:187
#define DM_PELSWIDTH
Definition: wingdi.h:1268
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define SM_CXSCREEN
Definition: winuser.h:949
#define CDS_UPDATEREGISTRY
Definition: winuser.h:181
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
smooth NULL
Definition: ftsmooth.c:416
PDEVMODEW pdmwDev
Definition: pdevobj.h:130
#define CDS_GLOBAL
Definition: winuser.h:184
VOID UserUpdateFullscreen(DWORD flags)
Definition: display.c:710
BOOL APIENTRY UserClipCursor(RECTL *prcl)
Definition: cursoricon.c:700
#define SM_CYSCREEN
Definition: winuser.h:950
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HDC hSystemBM
Definition: stockobj.c:52
#define RC_PALETTE
Definition: wingdi.h:789
WORD dmSize
Definition: wingdi.h:1619
BOOL NTAPI InitMetrics(VOID)
Definition: metric.c:19
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
ULONG flRaster
Definition: winddi.h:887
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1271
ULONG cBitsPixel
Definition: winddi.h:884
PDEVMODEW NTAPI PDEVOBJ_pdmMatchDevMode(PPDEVOBJ ppdev, PDEVMODEW pdm)
Definition: pdevobj.c:307
VOID APIENTRY UserRedrawDesktop(VOID)
Definition: desktop.c:1561
#define ERR(fmt,...)
Definition: debug.h:110
DWORD dmDisplayFrequency
Definition: wingdi.h:1653
#define DM_PELSHEIGHT
Definition: wingdi.h:1269
#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:545
#define CDS_NORESET
Definition: winuser.h:189
#define PUSIF_PALETTEDISPLAY
Definition: ntuser.h:954
#define DM_BITSPERPEL
Definition: wingdi.h:1267
ULONG ulVertRes
Definition: winddi.h:883
#define CDS_TEST
Definition: winuser.h:182
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:93
PCURICON_OBJECT FASTCALL UserSetCursor(PCURICON_OBJECT NewCursor, BOOL ForceChange)
Definition: msgqueue.c:93
#define HWND_BROADCAST
Definition: winuser.h:1190
PPDEVOBJ NTAPI EngpGetPDEV(_In_opt_ PUNICODE_STRING pustrDeviceName)
Definition: pdevobj.c:595

Referenced by NtUserChangeDisplaySettings(), and UserDisplayNotifyShutdown().

◆ UserDisplayNotifyShutdown()

VOID UserDisplayNotifyShutdown ( PPROCESSINFO  ppiCurrent)

Definition at line 931 of file display.c.

933 {
934  if (ppiCurrent == gpFullscreen)
935  {
937  if (gpFullscreen)
938  ERR("Failed to restore display mode!\n");
939  }
940 }
static PPROCESSINFO gpFullscreen
Definition: display.c:13
smooth NULL
Definition: ftsmooth.c:416
LONG APIENTRY UserChangeDisplaySettings(PUNICODE_STRING pustrDevice, LPDEVMODEW pdm, DWORD flags, LPVOID lParam)
Definition: display.c:721
#define ERR(fmt,...)
Definition: debug.h:110

Referenced by ExitThreadCallback().

◆ UserEnumCurrentDisplaySettings()

NTSTATUS NTAPI UserEnumCurrentDisplaySettings ( PUNICODE_STRING  pustrDevice,
PDEVMODEW ppdm 
)

Definition at line 462 of file display.c.

465 {
466  PPDEVOBJ ppdev;
467 
468  /* Get the PDEV for the device */
469  ppdev = EngpGetPDEV(pustrDevice);
470  if (!ppdev)
471  {
472  /* No device found */
473  ERR("No PDEV found!\n");
475  }
476 
477  *ppdm = ppdev->pdmwDev;
478  PDEVOBJ_vRelease(ppdev);
479 
480  return STATUS_SUCCESS;
481 }
PDEVMODEW pdmwDev
Definition: pdevobj.h:130
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
#define ERR(fmt,...)
Definition: debug.h:110
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:93
return STATUS_SUCCESS
Definition: btrfs.c:3014
PPDEVOBJ NTAPI EngpGetPDEV(_In_opt_ PUNICODE_STRING pustrDeviceName)
Definition: pdevobj.c:595

Referenced by NtUserEnumDisplaySettings().

◆ UserEnumDisplayDevices()

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

Definition at line 318 of file display.c.

323 {
324  PGRAPHICS_DEVICE pGraphicsDevice;
325  ULONG cbSize;
326  HKEY hkey;
328 
329  /* Ask gdi for the GRAPHICS_DEVICE */
330  pGraphicsDevice = EngpFindGraphicsDevice(pustrDevice, iDevNum, 0);
331  if (!pGraphicsDevice)
332  {
333  /* No device found */
334  ERR("No GRAPHICS_DEVICE found\n");
335  return STATUS_UNSUCCESSFUL;
336  }
337 
338  /* Open the device map registry key */
339  Status = RegOpenKey(KEY_VIDEO, &hkey);
340  if (!NT_SUCCESS(Status))
341  {
342  /* No device found */
343  ERR("Could not open reg key\n");
344  return STATUS_UNSUCCESSFUL;
345  }
346 
347  /* Query the registry path */
348  cbSize = sizeof(pdispdev->DeviceKey);
349  RegQueryValue(hkey,
350  pGraphicsDevice->szNtDeviceName,
351  REG_SZ,
352  pdispdev->DeviceKey,
353  &cbSize);
354 
355  /* Close registry key */
356  ZwClose(hkey);
357 
358  /* Copy device name, device string and StateFlags */
359  RtlStringCbCopyW(pdispdev->DeviceName, sizeof(pdispdev->DeviceName), pGraphicsDevice->szWinDeviceName);
360  RtlStringCbCopyW(pdispdev->DeviceString, sizeof(pdispdev->DeviceString), pGraphicsDevice->pwszDescription);
361  pdispdev->StateFlags = pGraphicsDevice->StateFlags;
362  // FIXME: fill in DEVICE ID
363  pdispdev->DeviceID[0] = UNICODE_NULL;
364 
365  return STATUS_SUCCESS;
366 }
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
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:2818
LONG NTSTATUS
Definition: precomp.h:26
WCHAR DeviceName[32]
Definition: wingdi.h:2817
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum, _In_ DWORD dwFlags)
Definition: device.c:369
#define UNICODE_NULL
WCHAR DeviceID[128]
Definition: wingdi.h:2820
LPWSTR pwszDescription
Definition: pdevobj.h:72
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
DWORD StateFlags
Definition: wingdi.h:2819
WCHAR DeviceKey[128]
Definition: wingdi.h:2821
#define ERR(fmt,...)
Definition: debug.h:110
#define RegQueryValue
Definition: winreg.h:523
unsigned int ULONG
Definition: retypes.h:1
#define RegOpenKey
Definition: winreg.h:519
return STATUS_SUCCESS
Definition: btrfs.c:3014
#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 485 of file display.c.

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

Referenced by NtUserEnumDisplaySettings().

◆ UserEnumRegistryDisplaySettings()

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

Definition at line 576 of file display.c.

579 {
580  HKEY hkey;
581  NTSTATUS Status = UserOpenDisplaySettingsKey(&hkey, pustrDevice, 0);
582  if(NT_SUCCESS(Status))
583  {
584  RegReadDisplaySettings(hkey, pdm);
585  ZwClose(hkey);
586  return STATUS_SUCCESS;
587  }
588  return Status;
589 }
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
VOID RegReadDisplaySettings(HKEY hkey, PDEVMODEW pdm)
Definition: display.c:35
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI UserOpenDisplaySettingsKey(OUT PHKEY phkey, IN PUNICODE_STRING pustrDevice, IN BOOL bGlobal)
Definition: display.c:545
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by NtUserEnumDisplaySettings(), and UserChangeDisplaySettings().

◆ UserOpenDisplaySettingsKey()

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

Definition at line 545 of file display.c.

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

Referenced by UserChangeDisplaySettings(), and UserEnumRegistryDisplaySettings().

◆ UserRefreshDisplay()

VOID UserRefreshDisplay ( IN PPDEVOBJ  ppdev)

Definition at line 278 of file display.c.

279 {
280  ULONG_PTR ulResult;
281  // PVOID pvOldCursor;
282 
283  // TODO: Re-enable the cursor reset code once this function becomes called
284  // from within a Win32 thread... Indeed UserSetCursor() requires this, but
285  // at the moment this function is directly called from a separate thread
286  // from within videoprt, instead of by a separate win32k system thread.
287 
288  if (!ppdev)
289  return;
290 
291  PDEVOBJ_vReference(ppdev);
292 
293  /* Remove mouse pointer */
294  // pvOldCursor = UserSetCursor(NULL, TRUE);
295 
296  /* Do the mode switch -- Use the actual same current mode */
297  ulResult = PDEVOBJ_bSwitchMode(ppdev, ppdev->pdmwDev);
298  ASSERT(ulResult);
299 
300  /* Restore mouse pointer, no hooks called */
301  // pvOldCursor = UserSetCursor(pvOldCursor, TRUE);
302  // ASSERT(pvOldCursor == NULL);
303 
304  /* Update the system metrics */
305  InitMetrics();
306 
307  /* Set new size of the monitor */
308  // UserUpdateMonitorSize((HDEV)ppdev);
309 
310  //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
312 
313  PDEVOBJ_vRelease(ppdev);
314 }
BOOL NTAPI PDEVOBJ_bSwitchMode(PPDEVOBJ ppdev, PDEVMODEW pdm)
Definition: pdevobj.c:509
FORCEINLINE VOID PDEVOBJ_vReference(_In_ PPDEVOBJ ppdev)
Definition: pdevobj.h:167
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOL NTAPI InitMetrics(VOID)
Definition: metric.c:19
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID APIENTRY UserRedrawDesktop(VOID)
Definition: desktop.c:1561
VOID NTAPI PDEVOBJ_vRelease(_Inout_ PPDEVOBJ ppdev)
Definition: pdevobj.c:93

Referenced by VideoPortCallout().

◆ UserUpdateFullscreen()

VOID UserUpdateFullscreen ( DWORD  flags)

Definition at line 710 of file display.c.

712 {
713  if (flags & CDS_FULLSCREEN)
715  else
716  gpFullscreen = NULL;
717 }
#define CDS_FULLSCREEN
Definition: winuser.h:183
PPROCESSINFO ppi
Definition: win32.h:87
static PPROCESSINFO gpFullscreen
Definition: display.c:13
smooth NULL
Definition: ftsmooth.c:416
PTHREADINFO gptiCurrent
Definition: ntuser.c:15
GLbitfield flags
Definition: glext.h:7161

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 InitVideo(), and UserEnumDisplayDevices().