ReactOS  0.4.15-dev-3177-gd6a0299
device.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TAG_GDEV   'gdev'
 

Functions

VOID NTAPI PDEVOBJ_vRefreshModeList (PPDEVOBJ ppdev)
 
VOID APIENTRY EngFileWrite (_In_ PFILE_OBJECT pFileObject, _In_reads_(nLength) PVOID lpBuffer, _In_ SIZE_T nLength, _Out_ PSIZE_T lpBytesWritten)
 
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice (_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum, _In_ DWORD dwFlags)
 
PGRAPHICS_DEVICE NTAPI EngpRegisterGraphicsDevice (_In_ PUNICODE_STRING pustrDeviceName, _In_ PUNICODE_STRING pustrDiplayDrivers, _In_ PUNICODE_STRING pustrDescription, _In_ PDEVMODEW pdmDefault)
 
BOOLEAN EngpPopulateDeviceModeList (_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault)
 
NTSTATUS EngpUpdateGraphicsDeviceList (VOID)
 
NTSTATUS NTAPI InitDeviceImpl (VOID)
 

Variables

PGRAPHICS_DEVICE gpPrimaryGraphicsDevice
 
PGRAPHICS_DEVICE gpVgaGraphicsDevice
 

Macro Definition Documentation

◆ TAG_GDEV

#define TAG_GDEV   'gdev'

Definition at line 4 of file device.h.

Function Documentation

◆ EngFileWrite()

VOID APIENTRY EngFileWrite ( _In_ PFILE_OBJECT  pFileObject,
_In_reads_(nLength) PVOID  lpBuffer,
_In_ SIZE_T  nLength,
_Out_ PSIZE_T  lpBytesWritten 
)

Definition at line 572 of file device.c.

577 {
579 
580  status = EngpFileIoRequest(pFileObject,
581  IRP_MJ_WRITE,
582  lpBuffer,
583  nLength,
584  0,
585  lpBytesWritten);
586  if (!NT_SUCCESS(status))
587  {
588  *lpBytesWritten = 0;
589  }
590 }
LONG NTSTATUS
Definition: precomp.h:26
_In_ DWORD nLength
Definition: wincon.h:473
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
static SERVICE_STATUS status
Definition: service.c:31
static NTSTATUS EngpFileIoRequest(_In_ PFILE_OBJECT pFileObject, _In_ ULONG ulMajorFunction, _In_reads_(nBufferSize) PVOID lpBuffer, _In_ SIZE_T nBufferSize, _In_ ULONGLONG ullStartOffset, _Out_ PULONG_PTR lpInformation)
Definition: device.c:514
Definition: ps.c:97

◆ EngpFindGraphicsDevice()

PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice ( _In_opt_ PUNICODE_STRING  pustrDevice,
_In_ ULONG  iDevNum,
_In_ DWORD  dwFlags 
)

Definition at line 469 of file device.c.

473 {
474  UNICODE_STRING ustrCurrent;
475  PGRAPHICS_DEVICE pGraphicsDevice;
476  ULONG i;
477  TRACE("EngpFindGraphicsDevice('%wZ', %lu, 0x%lx)\n",
478  pustrDevice, iDevNum, dwFlags);
479 
480  /* Lock list */
482 
483  if (pustrDevice && pustrDevice->Buffer)
484  {
485  /* Loop through the list of devices */
486  for (pGraphicsDevice = gpGraphicsDeviceFirst;
487  pGraphicsDevice;
488  pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice)
489  {
490  /* Compare the device name */
491  RtlInitUnicodeString(&ustrCurrent, pGraphicsDevice->szWinDeviceName);
492  if (RtlEqualUnicodeString(&ustrCurrent, pustrDevice, FALSE))
493  {
494  break;
495  }
496  }
497  }
498  else
499  {
500  /* Loop through the list of devices */
501  for (pGraphicsDevice = gpGraphicsDeviceFirst, i = 0;
502  pGraphicsDevice && i < iDevNum;
503  pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice, i++);
504  }
505 
506  /* Unlock list */
508 
509  return pGraphicsDevice;
510 }
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
#define FALSE
Definition: types.h:117
static PGRAPHICS_DEVICE gpGraphicsDeviceFirst
Definition: device.c:18
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
#define TRACE(s)
Definition: solgame.cpp:4
struct _GRAPHICS_DEVICE * pNextGraphicsDevice
Definition: pdevobj.h:61
static HSEMAPHORE ghsemGraphicsDeviceList
Definition: device.c:20
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
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
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)

Referenced by co_IntInitializeDesktopGraphics(), EngpCreatePDEV(), EngpUpdateGraphicsDeviceList(), UserEnumDisplayDevices(), and UserEnumDisplaySettings().

◆ EngpPopulateDeviceModeList()

BOOLEAN EngpPopulateDeviceModeList ( _Inout_ PGRAPHICS_DEVICE  pGraphicsDevice,
_In_ PDEVMODEW  pdmDefault 
)

Definition at line 125 of file device.c.

128 {
129  PWSTR pwsz;
130  PLDEVOBJ pldev;
131  PDEVMODEINFO pdminfo;
132  PDEVMODEW pdm, pdmEnd;
133  ULONG i, cModes = 0;
134  BOOLEAN bModeMatch = FALSE;
135 
136  ASSERT(pGraphicsDevice->pdevmodeInfo == NULL);
137  ASSERT(pGraphicsDevice->pDevModeList == NULL);
138 
139  pwsz = pGraphicsDevice->pDiplayDrivers;
140 
141  /* Loop through the driver names
142  * This is a REG_MULTI_SZ string */
143  for (; *pwsz; pwsz += wcslen(pwsz) + 1)
144  {
145  /* Try to load the display driver */
146  TRACE("Trying driver: %ls\n", pwsz);
147  pldev = EngLoadImageEx(pwsz, LDEV_DEVICE_DISPLAY);
148  if (!pldev)
149  {
150  ERR("Could not load driver: '%ls'\n", pwsz);
151  continue;
152  }
153 
154  /* Get the mode list from the driver */
155  pdminfo = LDEVOBJ_pdmiGetModes(pldev, pGraphicsDevice->DeviceObject);
156  if (!pdminfo)
157  {
158  ERR("Could not get mode list for '%ls'\n", pwsz);
159  continue;
160  }
161 
162  /* Attach the mode info to the device */
163  pdminfo->pdmiNext = pGraphicsDevice->pdevmodeInfo;
164  pGraphicsDevice->pdevmodeInfo = pdminfo;
165 
166  /* Loop all DEVMODEs */
167  pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
168  for (pdm = pdminfo->adevmode;
169  (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
170  pdm = (DEVMODEW*)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
171  {
172  /* Count this DEVMODE */
173  cModes++;
174 
175  /* Some drivers like the VBox driver don't fill the dmDeviceName
176  with the name of the display driver. So fix that here. */
177  RtlStringCbCopyW(pdm->dmDeviceName, sizeof(pdm->dmDeviceName), pwsz);
178  }
179 
180  // FIXME: release the driver again until it's used?
181  }
182 
183  if (!pGraphicsDevice->pdevmodeInfo || cModes == 0)
184  {
185  ERR("No devmodes\n");
186  return FALSE;
187  }
188 
189  /* Allocate an index buffer */
190  pGraphicsDevice->cDevModes = cModes;
191  pGraphicsDevice->pDevModeList = ExAllocatePoolWithTag(PagedPool,
192  cModes * sizeof(DEVMODEENTRY),
194  if (!pGraphicsDevice->pDevModeList)
195  {
196  ERR("No devmode list\n");
197  return FALSE;
198  }
199 
200  TRACE("Looking for mode %lux%lux%lu(%lu Hz)\n",
201  pdmDefault->dmPelsWidth,
202  pdmDefault->dmPelsHeight,
203  pdmDefault->dmBitsPerPel,
204  pdmDefault->dmDisplayFrequency);
205 
206  /* Loop through all DEVMODEINFOs */
207  for (pdminfo = pGraphicsDevice->pdevmodeInfo, i = 0;
208  pdminfo;
209  pdminfo = pdminfo->pdmiNext)
210  {
211  /* Calculate End of the DEVMODEs */
212  pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
213 
214  /* Loop through the DEVMODEs */
215  for (pdm = pdminfo->adevmode;
216  (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
217  pdm = (PDEVMODEW)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
218  {
219  TRACE(" %S has mode %lux%lux%lu(%lu Hz)\n",
220  pdm->dmDeviceName,
221  pdm->dmPelsWidth,
222  pdm->dmPelsHeight,
223  pdm->dmBitsPerPel,
224  pdm->dmDisplayFrequency);
225  /* Compare with the default entry */
226  if (!bModeMatch &&
227  pdm->dmBitsPerPel == pdmDefault->dmBitsPerPel &&
228  pdm->dmPelsWidth == pdmDefault->dmPelsWidth &&
229  pdm->dmPelsHeight == pdmDefault->dmPelsHeight)
230  {
231  pGraphicsDevice->iDefaultMode = i;
232  pGraphicsDevice->iCurrentMode = i;
233  TRACE("Found default entry: %lu '%ls'\n", i, pdm->dmDeviceName);
234  if (pdm->dmDisplayFrequency == pdmDefault->dmDisplayFrequency)
235  {
236  /* Uh oh, even the display frequency matches. */
237  bModeMatch = TRUE;
238  }
239  }
240 
241  /* Initialize the entry */
242  pGraphicsDevice->pDevModeList[i].dwFlags = 0;
243  pGraphicsDevice->pDevModeList[i].pdm = pdm;
244  i++;
245  }
246  }
247  return TRUE;
248 }
signed char * PCHAR
Definition: retypes.h:7
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
struct _devicemodeW * PDEVMODEW
PDEVMODEINFO NTAPI LDEVOBJ_pdmiGetModes(_In_ PLDEVOBJ pldev, _In_ HANDLE hDriver)
Definition: ldevobj.c:116
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
WORD dmDriverExtra
Definition: wingdi.h:1620
DWORD dmBitsPerPel
Definition: wingdi.h:1646
PLDEVOBJ NTAPI EngLoadImageEx(_In_z_ LPWSTR pwszDriverName, _In_ ULONG ldevtype)
Definition: ldevobj.c:328
#define FALSE
Definition: types.h:117
ULONG cbdevmode
Definition: pdevobj.h:46
unsigned char BOOLEAN
DEVMODEW adevmode[1]
Definition: pdevobj.h:47
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
struct _DEVMODEINFO * pdmiNext
Definition: pdevobj.h:44
WORD dmSize
Definition: wingdi.h:1619
WCHAR dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1616
DWORD dmPelsWidth
Definition: wingdi.h:1647
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define GDITAG_GDEVICE
Definition: tags.h:98
#define ERR(fmt,...)
Definition: debug.h:110
DWORD dmDisplayFrequency
Definition: wingdi.h:1653
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
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
DWORD dmPelsHeight
Definition: wingdi.h:1648
unsigned int ULONG
Definition: retypes.h:1

Referenced by EngpRegisterGraphicsDevice(), and PDEVOBJ_vRefreshModeList().

◆ EngpRegisterGraphicsDevice()

PGRAPHICS_DEVICE NTAPI EngpRegisterGraphicsDevice ( _In_ PUNICODE_STRING  pustrDeviceName,
_In_ PUNICODE_STRING  pustrDiplayDrivers,
_In_ PUNICODE_STRING  pustrDescription,
_In_ PDEVMODEW  pdmDefault 
)

Definition at line 316 of file device.c.

321 {
322  PGRAPHICS_DEVICE pGraphicsDevice;
324  PFILE_OBJECT pFileObject;
326  VIDEO_WIN32K_CALLBACKS Win32kCallbacks;
327  ULONG ulReturn;
328  PWSTR pwsz;
329  ULONG cj;
330 
331  TRACE("EngpRegisterGraphicsDevice(%wZ)\n", pustrDeviceName);
332 
333  /* Allocate a GRAPHICS_DEVICE structure */
334  pGraphicsDevice = ExAllocatePoolWithTag(PagedPool,
335  sizeof(GRAPHICS_DEVICE),
337  if (!pGraphicsDevice)
338  {
339  ERR("ExAllocatePoolWithTag failed\n");
340  return NULL;
341  }
342 
343  /* Try to open and enable the device */
344  Status = IoGetDeviceObjectPointer(pustrDeviceName,
346  &pFileObject,
347  &pDeviceObject);
348  if (!NT_SUCCESS(Status))
349  {
350  ERR("Could not open device %wZ, 0x%lx\n", pustrDeviceName, Status);
351  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
352  return NULL;
353  }
354 
355  /* Copy the device and file object pointers */
356  pGraphicsDevice->DeviceObject = pDeviceObject;
357  pGraphicsDevice->FileObject = pFileObject;
358 
359  /* Initialize and register the device with videoprt for Win32k callbacks */
360  Win32kCallbacks.PhysDisp = pGraphicsDevice;
361  Win32kCallbacks.Callout = VideoPortCallout;
362  // Reset the data being returned prior to the call.
363  Win32kCallbacks.bACPI = FALSE;
364  Win32kCallbacks.pPhysDeviceObject = NULL;
365  Win32kCallbacks.DualviewFlags = 0;
366  Status = (NTSTATUS)EngDeviceIoControl((HANDLE)pDeviceObject,
368  &Win32kCallbacks,
369  sizeof(Win32kCallbacks),
370  &Win32kCallbacks,
371  sizeof(Win32kCallbacks),
372  &ulReturn);
373  if (Status != ERROR_SUCCESS)
374  {
375  ERR("EngDeviceIoControl(0x%p, IOCTL_VIDEO_INIT_WIN32K_CALLBACKS) failed, Status 0x%lx\n",
377  }
378  // TODO: Set flags according to the results.
379  // if (Win32kCallbacks.bACPI)
380  // if (Win32kCallbacks.DualviewFlags & ???)
381  // Win32kCallbacks.pPhysDeviceObject;
382 
383  /* Copy the device name */
384  RtlStringCbCopyNW(pGraphicsDevice->szNtDeviceName,
385  sizeof(pGraphicsDevice->szNtDeviceName),
386  pustrDeviceName->Buffer,
387  pustrDeviceName->Length);
388 
389  /* Create a Win32 device name (FIXME: virtual devices!) */
390  RtlStringCbPrintfW(pGraphicsDevice->szWinDeviceName,
391  sizeof(pGraphicsDevice->szWinDeviceName),
392  L"\\\\.\\DISPLAY%d",
393  (int)giDevNum);
394 
395  /* Allocate a buffer for the strings */
396  cj = pustrDiplayDrivers->Length + pustrDescription->Length + sizeof(WCHAR);
398  if (!pwsz)
399  {
400  ERR("Could not allocate string buffer\n");
401  ASSERT(FALSE); // FIXME
402  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
403  return NULL;
404  }
405 
406  /* Copy the display driver names */
407  pGraphicsDevice->pDiplayDrivers = pwsz;
408  RtlCopyMemory(pGraphicsDevice->pDiplayDrivers,
409  pustrDiplayDrivers->Buffer,
410  pustrDiplayDrivers->Length);
411 
412  /* Copy the description */
413  pGraphicsDevice->pwszDescription = pwsz + pustrDiplayDrivers->Length / sizeof(WCHAR);
414  RtlCopyMemory(pGraphicsDevice->pwszDescription,
415  pustrDescription->Buffer,
416  pustrDescription->Length);
417  pGraphicsDevice->pwszDescription[pustrDescription->Length/sizeof(WCHAR)] = 0;
418 
419  /* Initialize the pdevmodeInfo list and default index */
420  pGraphicsDevice->pdevmodeInfo = NULL;
421  pGraphicsDevice->iDefaultMode = 0;
422  pGraphicsDevice->iCurrentMode = 0;
423 
424  // FIXME: initialize state flags
425  pGraphicsDevice->StateFlags = 0;
426 
427  /* Create the mode list */
428  pGraphicsDevice->pDevModeList = NULL;
429  if (!EngpPopulateDeviceModeList(pGraphicsDevice, pdmDefault))
430  {
431  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
432  return NULL;
433  }
434 
435  /* Lock loader */
437 
438  /* Insert the device into the global list */
439  pGraphicsDevice->pNextGraphicsDevice = NULL;
441  gpGraphicsDeviceLast->pNextGraphicsDevice = pGraphicsDevice;
442  gpGraphicsDeviceLast = pGraphicsDevice;
444  gpGraphicsDeviceFirst = pGraphicsDevice;
445 
446  /* Increment the device number */
447  giDevNum++;
448 
449  /* Unlock loader */
451  TRACE("Prepared %lu modes for %ls\n", pGraphicsDevice->cDevModes, pGraphicsDevice->pwszDescription);
452 
453  /* HACK: already in graphic mode; display wallpaper on this new display */
455  {
456  UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY");
457  UNICODE_STRING DisplayName;
458  HDC hdc;
459  RtlInitUnicodeString(&DisplayName, pGraphicsDevice->szWinDeviceName);
460  hdc = IntGdiCreateDC(&DriverName, &DisplayName, NULL, NULL, FALSE);
462  }
463 
464  return pGraphicsDevice;
465 }
BOOLEAN EngpPopulateDeviceModeList(_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault)
Definition: device.c:125
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
_In_ ULONG cj
Definition: winddi.h:3540
static PGRAPHICS_DEVICE gpGraphicsDeviceLast
Definition: device.c:19
#define ERROR_SUCCESS
Definition: deptool.c:10
PDEVICE_OBJECT DeviceObject
Definition: pdevobj.h:63
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
WCHAR szNtDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:59
uint16_t * PWSTR
Definition: typedefs.h:56
DWORD StateFlags
Definition: pdevobj.h:66
LONG NTSTATUS
Definition: precomp.h:26
static HDC
Definition: imagelist.c:92
PDEVMODEENTRY pDevModeList
Definition: pdevobj.h:70
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
IN PVIDEO_WIN32K_CALLOUT Callout
Definition: ntddvdeo.h:263
#define FALSE
Definition: types.h:117
#define IOCTL_VIDEO_INIT_WIN32K_CALLBACKS
Definition: ntddvdeo.h:62
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSTRSAFEAPI RtlStringCbCopyNW(_Out_writes_bytes_(cbDest) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToCopy) STRSAFE_LPCWSTR pszSrc, _In_ size_t cbToCopy)
Definition: ntstrsafe.h:416
LPWSTR pwszDescription
Definition: pdevobj.h:72
VOID NTAPI VideoPortCallout(_In_ PVOID Params)
Definition: device.c:256
static PGRAPHICS_DEVICE gpGraphicsDeviceFirst
Definition: device.c:18
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
BOOL FASTCALL IntPaintDesktop(HDC hDC)
Definition: desktop.c:1795
#define FILE_WRITE_DATA
Definition: nt_native.h:631
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
struct _GRAPHICS_DEVICE * pNextGraphicsDevice
Definition: pdevobj.h:61
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG iCurrentMode
Definition: pdevobj.h:78
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
LPWSTR pDiplayDrivers
Definition: pdevobj.h:71
ULONG cDevModes
Definition: pdevobj.h:69
OUT HANDLE pPhysDeviceObject
Definition: ntddvdeo.h:265
static HSEMAPHORE ghsemGraphicsDeviceList
Definition: device.c:20
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
HDC hdc
Definition: main.c:9
#define NTSTATUS
Definition: precomp.h:20
#define GDITAG_DRVSUP
Definition: tags.h:76
#define GDITAG_GDEVICE
Definition: tags.h:98
OUT ULONG DualviewFlags
Definition: ntddvdeo.h:266
#define ERR(fmt,...)
Definition: debug.h:110
static ULONG giDevNum
Definition: device.c:21
HDC FASTCALL IntGdiCreateDC(PUNICODE_STRING Driver, PUNICODE_STRING pustrDevice, PVOID pUMdhpdev, CONST PDEVMODEW pdmInit, BOOL CreateAsIC)
Definition: dclife.c:1040
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
HDC ScreenDeviceContext
Definition: desktop.c:36
PDEVMODEINFO pdevmodeInfo
Definition: pdevobj.h:68
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ULONG iDefaultMode
Definition: pdevobj.h:77
PFILE_OBJECT FileObject
Definition: pdevobj.h:75
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by InitDisplayDriver().

◆ EngpUpdateGraphicsDeviceList()

NTSTATUS EngpUpdateGraphicsDeviceList ( VOID  )

Definition at line 36 of file device.c.

37 {
38  ULONG iDevNum, iVGACompatible = -1, ulMaxObjectNumber = 0;
39  WCHAR awcDeviceName[20];
40  UNICODE_STRING ustrDeviceName;
41  WCHAR awcBuffer[256];
43  PGRAPHICS_DEVICE pGraphicsDevice;
44  ULONG cbValue;
45  HKEY hkey;
46 
47  /* Open the key for the adapters */
48  Status = RegOpenKey(L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO", &hkey);
49  if (!NT_SUCCESS(Status))
50  {
51  ERR("Could not open HARDWARE\\DEVICEMAP\\VIDEO registry key:0x%lx\n", Status);
52  return Status;
53  }
54 
55  /* Read the name of the VGA adapter */
56  cbValue = sizeof(awcDeviceName);
57  Status = RegQueryValue(hkey, L"VgaCompatible", REG_SZ, awcDeviceName, &cbValue);
58  if (NT_SUCCESS(Status))
59  {
60  iVGACompatible = _wtoi(&awcDeviceName[sizeof("\\Device\\Video")-1]);
61  ERR("VGA adapter = %lu\n", iVGACompatible);
62  }
63 
64  /* Get the maximum mumber of adapters */
65  if (!RegReadDWORD(hkey, L"MaxObjectNumber", &ulMaxObjectNumber))
66  {
67  ERR("Could not read MaxObjectNumber, defaulting to 0.\n");
68  }
69 
70  TRACE("Found %lu devices\n", ulMaxObjectNumber + 1);
71 
72  /* Loop through all adapters */
73  for (iDevNum = 0; iDevNum <= ulMaxObjectNumber; iDevNum++)
74  {
75  /* Create the adapter's key name */
76  swprintf(awcDeviceName, L"\\Device\\Video%lu", iDevNum);
77  RtlInitUnicodeString(&ustrDeviceName, awcDeviceName);
78 
79  /* Check if the device exists already */
80  pGraphicsDevice = EngpFindGraphicsDevice(&ustrDeviceName, iDevNum, 0);
81  if (pGraphicsDevice != NULL)
82  {
83  continue;
84  }
85 
86  /* Read the reg key name */
87  cbValue = sizeof(awcBuffer);
88  Status = RegQueryValue(hkey, awcDeviceName, REG_SZ, awcBuffer, &cbValue);
89  if (!NT_SUCCESS(Status))
90  {
91  ERR("failed to query the registry path:0x%lx\n", Status);
92  continue;
93  }
94 
95  /* Initialize the driver for this device */
96  pGraphicsDevice = InitDisplayDriver(awcDeviceName, awcBuffer);
97  if (!pGraphicsDevice) continue;
98 
99  /* Check if this is a VGA compatible adapter */
100  if (pGraphicsDevice->StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE)
101  {
102  /* Save this as the VGA adapter */
103  if (!gpVgaGraphicsDevice)
104  {
105  gpVgaGraphicsDevice = pGraphicsDevice;
106  TRACE("gpVgaGraphicsDevice = %p\n", gpVgaGraphicsDevice);
107  }
108  }
109 
110  /* Set the first one as primary device */
112  {
113  gpPrimaryGraphicsDevice = pGraphicsDevice;
114  TRACE("gpPrimaryGraphicsDevice = %p\n", gpPrimaryGraphicsDevice);
115  }
116  }
117 
118  /* Close the device map registry key */
119  ZwClose(hkey);
120 
121  return STATUS_SUCCESS;
122 }
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
#define swprintf
Definition: precomp.h:40
PGRAPHICS_DEVICE NTAPI InitDisplayDriver(IN PWSTR pwszDeviceName, IN PWSTR pwszRegKey)
Definition: display.c:66
PGRAPHICS_DEVICE gpPrimaryGraphicsDevice
Definition: device.c:15
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum, _In_ DWORD dwFlags)
Definition: device.c:469
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
BOOL NTAPI RegReadDWORD(HKEY hkey, PWSTR pwszValue, PDWORD pdwData)
Definition: registry.c:150
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
#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 STATUS_SUCCESS
Definition: shellext.h:65
#define RegOpenKey
Definition: winreg.h:519
#define REG_SZ
Definition: layer.c:22

Referenced by InitVideo(), and UserEnumDisplayDevices().

◆ InitDeviceImpl()

NTSTATUS NTAPI InitDeviceImpl ( VOID  )

Definition at line 26 of file device.c.

27 {
31 
32  return STATUS_SUCCESS;
33 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
static HSEMAPHORE ghsemGraphicsDeviceList
Definition: device.c:20
HSEMAPHORE WINAPI EngCreateSemaphore(VOID)
Definition: eng.c:75
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by DriverEntry().

◆ PDEVOBJ_vRefreshModeList()

VOID NTAPI PDEVOBJ_vRefreshModeList ( PPDEVOBJ  ppdev)

Definition at line 264 of file pdevobj.c.

266 {
267  PGRAPHICS_DEVICE pGraphicsDevice;
268  PDEVMODEINFO pdminfo, pdmiNext;
269  DEVMODEW dmDefault;
270  DEVMODEW dmCurrent;
271 
272  /* Lock the PDEV */
274 
275  pGraphicsDevice = ppdev->pGraphicsDevice;
276 
277  /* Remember our default mode */
278  dmDefault = *pGraphicsDevice->pDevModeList[pGraphicsDevice->iDefaultMode].pdm;
279  dmCurrent = *ppdev->pdmwDev;
280 
281  /* Clear out the modes */
282  for (pdminfo = pGraphicsDevice->pdevmodeInfo;
283  pdminfo;
284  pdminfo = pdmiNext)
285  {
286  pdmiNext = pdminfo->pdmiNext;
288  }
289  pGraphicsDevice->pdevmodeInfo = NULL;
290  ExFreePoolWithTag(pGraphicsDevice->pDevModeList, GDITAG_GDEVICE);
291  pGraphicsDevice->pDevModeList = NULL;
292 
293  /* Now re-populate the list */
294  if (!EngpPopulateDeviceModeList(pGraphicsDevice, &dmDefault))
295  {
296  DPRINT1("FIXME: EngpPopulateDeviceModeList failed, we just destroyed a perfectly good mode list\n");
297  }
298 
299  ppdev->pdmwDev = PDEVOBJ_pdmMatchDevMode(ppdev, &dmCurrent);
300 
301  /* Unlock PDEV */
303 }
BOOLEAN EngpPopulateDeviceModeList(_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault)
Definition: device.c:125
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
#define GDITAG_DEVMODE
Definition: tags.h:73
PDEVMODEENTRY pDevModeList
Definition: pdevobj.h:70
PDEVMODEW pdm
Definition: pdevobj.h:53
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
PDEVMODEW pdmwDev
Definition: pdevobj.h:130
HSEMAPHORE hsemDevLock
Definition: pdevobj.h:91
struct _DEVMODEINFO * pdmiNext
Definition: pdevobj.h:44
PDEVMODEW NTAPI PDEVOBJ_pdmMatchDevMode(PPDEVOBJ ppdev, PDEVMODEW pdm)
Definition: pdevobj.c:307
#define GDITAG_GDEVICE
Definition: tags.h:98
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
PDEVMODEINFO pdevmodeInfo
Definition: pdevobj.h:68
PGRAPHICS_DEVICE pGraphicsDevice
Definition: pdevobj.h:128
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ULONG iDefaultMode
Definition: pdevobj.h:77

Referenced by UserEnumDisplaySettings().

Variable Documentation

◆ gpPrimaryGraphicsDevice

PGRAPHICS_DEVICE gpPrimaryGraphicsDevice

Definition at line 15 of file device.c.

Referenced by EngpCreatePDEV(), EngpUpdateGraphicsDeviceList(), and InitVideo().

◆ gpVgaGraphicsDevice

PGRAPHICS_DEVICE gpVgaGraphicsDevice

Definition at line 16 of file device.c.

Referenced by EngpUpdateGraphicsDeviceList(), and InitVideo().