ReactOS  0.4.14-dev-604-gcfdd483
device.c File Reference
#include <win32k.h>
#include <ntddvdeo.h>
Include dependency graph for device.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (EngDev)
 
INIT_FUNCTION NTSTATUS NTAPI InitDeviceImpl (VOID)
 
BOOLEAN EngpPopulateDeviceModeList (_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault)
 
VOID UserRefreshDisplay (IN PPDEVOBJ ppdev)
 
VOID NTAPI VideoPortCallout (_In_ PVOID Params)
 
PGRAPHICS_DEVICE NTAPI EngpRegisterGraphicsDevice (_In_ PUNICODE_STRING pustrDeviceName, _In_ PUNICODE_STRING pustrDiplayDrivers, _In_ PUNICODE_STRING pustrDescription, _In_ PDEVMODEW pdmDefault)
 
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice (_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum, _In_ DWORD dwFlags)
 
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)
 
VOID APIENTRY EngFileWrite (_In_ PFILE_OBJECT pFileObject, _In_reads_(nLength) PVOID lpBuffer, _In_ SIZE_T nLength, _Out_ PSIZE_T lpBytesWritten)
 
 _Success_ (return >=0) NTSTATUS APIENTRY EngFileIoControl(_In_ PFILE_OBJECT pFileObject
 
_In_ DWORD _In_reads_ (nInBufferSize)
 
 _Success_ (return==0)
 

Variables

PGRAPHICS_DEVICE gpPrimaryGraphicsDevice
 
PGRAPHICS_DEVICE gpVgaGraphicsDevice
 
static PGRAPHICS_DEVICE gpGraphicsDeviceFirst = NULL
 
static PGRAPHICS_DEVICE gpGraphicsDeviceLast = NULL
 
static HSEMAPHORE ghsemGraphicsDeviceList
 
static ULONG giDevNum = 1
 
_In_ DWORD dwIoControlCode
 

Function Documentation

◆ _In_reads_()

_In_ DWORD _In_reads_ ( nInBufferSize  )

Definition at line 498 of file device.c.

503 {
505  KEVENT Event;
506  PIRP pIrp;
509 
510  /* Get corresponding device object */
512  if (!pDeviceObject)
513  {
515  }
516 
517  /* Initialize an event */
519 
520  /* Build IO control IRP */
523  lpInBuffer,
524  (ULONG)nInBufferSize,
525  lpOutBuffer,
526  (ULONG)nOutBufferSize,
527  FALSE,
528  &Event,
529  &Iosb);
530  if (!pIrp)
531  {
533  }
534 
535  /* Call the driver */
537 
538  /* Wait if neccessary */
539  if (Status == STATUS_PENDING)
540  {
542  Status = Iosb.Status;
543  }
544 
545  /* Return information to the caller about the operation. */
546  *lpInformation = Iosb.Information;
547 
548  /* This function returns NTSTATUS */
549  return Status;
550 }
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
_In_ DWORD dwIoControlCode
Definition: device.c:497
return Iosb
Definition: create.c:4426
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
unsigned int ULONG
Definition: retypes.h:1

◆ _Success_() [1/2]

_Success_ ( return >=  0)

◆ _Success_() [2/2]

_Success_ ( return  = =0)

Definition at line 555 of file device.c.

566 {
567  PIRP Irp;
569  KEVENT Event;
572 
573  TRACE("EngDeviceIoControl() called\n");
574 
575  if (!hDevice)
576  {
577  return ERROR_INVALID_HANDLE;
578  }
579 
581 
582  DeviceObject = (PDEVICE_OBJECT) hDevice;
583 
585  DeviceObject,
586  lpInBuffer,
588  lpOutBuffer,
590  FALSE,
591  &Event,
592  &Iosb);
593  if (!Irp) return ERROR_NOT_ENOUGH_MEMORY;
594 
596 
597  if (Status == STATUS_PENDING)
598  {
600  Status = Iosb.Status;
601  }
602 
603  TRACE("EngDeviceIoControl(): Returning %X/%X\n", Iosb.Status,
604  Iosb.Information);
605 
606  /* Return information to the caller about the operation. */
607  *lpBytesReturned = (DWORD)Iosb.Information;
608 
609  /* Convert NT status values to win32 error codes. */
610  switch (Status)
611  {
614 
616  return ERROR_MORE_DATA;
617 
619  return ERROR_INVALID_FUNCTION;
620 
623 
626 
628  return ERROR_DEV_NOT_EXIST;
629 
630  case STATUS_PENDING:
631  return ERROR_IO_PENDING;
632  }
633 
634  return Status;
635 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:414
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ DWORD _In_ DWORD _In_ DWORD cjOutBufferSize
Definition: winddi.h:1704
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _DEVICE_OBJECT * PDEVICE_OBJECT
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
LONG NTSTATUS
Definition: precomp.h:26
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_IO_PENDING
Definition: dderror.h:15
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define DWORD
Definition: nt_native.h:44
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
_In_ DWORD _In_ DWORD cjInBufferSize
Definition: winddi.h:1702
switch(r->id)
Definition: btrfs.c:2904
_In_ DWORD dwIoControlCode
Definition: device.c:497
#define TRACE(s)
Definition: solgame.cpp:4
return Iosb
Definition: create.c:4426
#define STATUS_PENDING
Definition: ntstatus.h:82
#define VOID
Definition: acefi.h:82
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
_In_ DWORD _In_ DWORD _In_ DWORD _Out_ LPDWORD lpBytesReturned
Definition: winddi.h:1704
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define ERROR_DEV_NOT_EXIST
Definition: dderror.h:8
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( EngDev  )

◆ EngFileWrite()

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

Definition at line 472 of file device.c.

477 {
479 
480  status = EngpFileIoRequest(pFileObject,
481  IRP_MJ_WRITE,
482  lpBuffer,
483  nLength,
484  0,
485  lpBytesWritten);
486  if (!NT_SUCCESS(status))
487  {
488  *lpBytesWritten = 0;
489  }
490 }
LONG NTSTATUS
Definition: precomp.h:26
_In_ DWORD nLength
Definition: wincon.h:461
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#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:414
Definition: ps.c:97

◆ EngpFileIoRequest()

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 
)
static

Definition at line 414 of file device.c.

421 {
423  KEVENT Event;
424  PIRP pIrp;
427  LARGE_INTEGER liStartOffset;
428 
429  /* Get corresponding device object */
431  if (!pDeviceObject)
432  {
434  }
435 
436  /* Initialize an event */
438 
439  /* Build IRP */
440  liStartOffset.QuadPart = ullStartOffset;
441  pIrp = IoBuildSynchronousFsdRequest(ulMajorFunction,
443  lpBuffer,
444  (ULONG)nBufferSize,
445  &liStartOffset,
446  &Event,
447  &Iosb);
448  if (!pIrp)
449  {
451  }
452 
453  /* Call the driver */
455 
456  /* Wait if neccessary */
457  if (STATUS_PENDING == Status)
458  {
460  Status = Iosb.Status;
461  }
462 
463  /* Return information to the caller about the operation. */
464  *lpInformation = Iosb.Information;
465 
466  /* Return NTSTATUS */
467  return Status;
468 }
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
return Iosb
Definition: create.c:4426
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
unsigned int ULONG
Definition: retypes.h:1
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by EngFileWrite().

◆ EngpFindGraphicsDevice()

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

Definition at line 369 of file device.c.

373 {
374  UNICODE_STRING ustrCurrent;
375  PGRAPHICS_DEVICE pGraphicsDevice;
376  ULONG i;
377  TRACE("EngpFindGraphicsDevice('%wZ', %lu, 0x%lx)\n",
378  pustrDevice, iDevNum, dwFlags);
379 
380  /* Lock list */
382 
383  if (pustrDevice && pustrDevice->Buffer)
384  {
385  /* Loop through the list of devices */
386  for (pGraphicsDevice = gpGraphicsDeviceFirst;
387  pGraphicsDevice;
388  pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice)
389  {
390  /* Compare the device name */
391  RtlInitUnicodeString(&ustrCurrent, pGraphicsDevice->szWinDeviceName);
392  if (RtlEqualUnicodeString(&ustrCurrent, pustrDevice, FALSE))
393  {
394  break;
395  }
396  }
397  }
398  else
399  {
400  /* Loop through the list of devices */
401  for (pGraphicsDevice = gpGraphicsDeviceFirst, i = 0;
402  pGraphicsDevice && i < iDevNum;
403  pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice, i++);
404  }
405 
406  /* Unlock list */
408 
409  return pGraphicsDevice;
410 }
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
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
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
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 EngpCreatePDEV(), UserEnumDisplayDevices(), and UserEnumDisplaySettings().

◆ EngpPopulateDeviceModeList()

BOOLEAN EngpPopulateDeviceModeList ( _Inout_ PGRAPHICS_DEVICE  pGraphicsDevice,
_In_ PDEVMODEW  pdmDefault 
)

Definition at line 36 of file device.c.

39 {
40  PWSTR pwsz;
41  PLDEVOBJ pldev;
42  PDEVMODEINFO pdminfo;
43  PDEVMODEW pdm, pdmEnd;
44  ULONG i, cModes = 0;
45  BOOLEAN bModeMatch = FALSE;
46 
47  ASSERT(pGraphicsDevice->pdevmodeInfo == NULL);
48  ASSERT(pGraphicsDevice->pDevModeList == NULL);
49 
50  pwsz = pGraphicsDevice->pDiplayDrivers;
51 
52  /* Loop through the driver names
53  * This is a REG_MULTI_SZ string */
54  for (; *pwsz; pwsz += wcslen(pwsz) + 1)
55  {
56  /* Try to load the display driver */
57  TRACE("Trying driver: %ls\n", pwsz);
58  pldev = EngLoadImageEx(pwsz, LDEV_DEVICE_DISPLAY);
59  if (!pldev)
60  {
61  ERR("Could not load driver: '%ls'\n", pwsz);
62  continue;
63  }
64 
65  /* Get the mode list from the driver */
66  pdminfo = LDEVOBJ_pdmiGetModes(pldev, pGraphicsDevice->DeviceObject);
67  if (!pdminfo)
68  {
69  ERR("Could not get mode list for '%ls'\n", pwsz);
70  continue;
71  }
72 
73  /* Attach the mode info to the device */
74  pdminfo->pdmiNext = pGraphicsDevice->pdevmodeInfo;
75  pGraphicsDevice->pdevmodeInfo = pdminfo;
76 
77  /* Loop all DEVMODEs */
78  pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
79  for (pdm = pdminfo->adevmode;
80  (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
81  pdm = (DEVMODEW*)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
82  {
83  /* Count this DEVMODE */
84  cModes++;
85 
86  /* Some drivers like the VBox driver don't fill the dmDeviceName
87  with the name of the display driver. So fix that here. */
88  RtlStringCbCopyW(pdm->dmDeviceName, sizeof(pdm->dmDeviceName), pwsz);
89  }
90 
91  // FIXME: release the driver again until it's used?
92  }
93 
94  if (!pGraphicsDevice->pdevmodeInfo || cModes == 0)
95  {
96  ERR("No devmodes\n");
97  return FALSE;
98  }
99 
100  /* Allocate an index buffer */
101  pGraphicsDevice->cDevModes = cModes;
102  pGraphicsDevice->pDevModeList = ExAllocatePoolWithTag(PagedPool,
103  cModes * sizeof(DEVMODEENTRY),
105  if (!pGraphicsDevice->pDevModeList)
106  {
107  ERR("No devmode list\n");
108  return FALSE;
109  }
110 
111  TRACE("Looking for mode %lux%lux%lu(%lu Hz)\n",
112  pdmDefault->dmPelsWidth,
113  pdmDefault->dmPelsHeight,
114  pdmDefault->dmBitsPerPel,
115  pdmDefault->dmDisplayFrequency);
116 
117  /* Loop through all DEVMODEINFOs */
118  for (pdminfo = pGraphicsDevice->pdevmodeInfo, i = 0;
119  pdminfo;
120  pdminfo = pdminfo->pdmiNext)
121  {
122  /* Calculate End of the DEVMODEs */
123  pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
124 
125  /* Loop through the DEVMODEs */
126  for (pdm = pdminfo->adevmode;
127  (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
128  pdm = (PDEVMODEW)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
129  {
130  TRACE(" %S has mode %lux%lux%lu(%lu Hz)\n",
131  pdm->dmDeviceName,
132  pdm->dmPelsWidth,
133  pdm->dmPelsHeight,
134  pdm->dmBitsPerPel,
135  pdm->dmDisplayFrequency);
136  /* Compare with the default entry */
137  if (!bModeMatch &&
138  pdm->dmBitsPerPel == pdmDefault->dmBitsPerPel &&
139  pdm->dmPelsWidth == pdmDefault->dmPelsWidth &&
140  pdm->dmPelsHeight == pdmDefault->dmPelsHeight)
141  {
142  pGraphicsDevice->iDefaultMode = i;
143  pGraphicsDevice->iCurrentMode = i;
144  TRACE("Found default entry: %lu '%ls'\n", i, pdm->dmDeviceName);
145  if (pdm->dmDisplayFrequency == pdmDefault->dmDisplayFrequency)
146  {
147  /* Uh oh, even the display frequency matches. */
148  bModeMatch = TRUE;
149  }
150  }
151 
152  /* Initialize the entry */
153  pGraphicsDevice->pDevModeList[i].dwFlags = 0;
154  pGraphicsDevice->pDevModeList[i].pdm = pdm;
155  i++;
156  }
157  }
158  return TRUE;
159 }
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
#define TRUE
Definition: types.h:120
struct _devicemodeW * PDEVMODEW
PDEVMODEINFO NTAPI LDEVOBJ_pdmiGetModes(_In_ PLDEVOBJ pldev, _In_ HANDLE hDriver)
Definition: ldevobj.c:116
uint16_t * PWSTR
Definition: typedefs.h:54
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
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
ULONG cbdevmode
Definition: pdevobj.h:46
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
DEVMODEW adevmode[1]
Definition: pdevobj.h:47
#define TRACE(s)
Definition: solgame.cpp:4
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define GDITAG_GDEVICE
Definition: tags.h:98
#define ERR(fmt,...)
Definition: debug.h:109
DWORD dmDisplayFrequency
Definition: wingdi.h:1653
DWORD dmPelsHeight
Definition: wingdi.h:1648
unsigned int ULONG
Definition: retypes.h:1
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

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 227 of file device.c.

232 {
233  PGRAPHICS_DEVICE pGraphicsDevice;
235  PFILE_OBJECT pFileObject;
237  VIDEO_WIN32K_CALLBACKS Win32kCallbacks;
238  ULONG ulReturn;
239  PWSTR pwsz;
240  ULONG cj;
241 
242  TRACE("EngpRegisterGraphicsDevice(%wZ)\n", pustrDeviceName);
243 
244  /* Allocate a GRAPHICS_DEVICE structure */
245  pGraphicsDevice = ExAllocatePoolWithTag(PagedPool,
246  sizeof(GRAPHICS_DEVICE),
248  if (!pGraphicsDevice)
249  {
250  ERR("ExAllocatePoolWithTag failed\n");
251  return NULL;
252  }
253 
254  /* Try to open and enable the device */
255  Status = IoGetDeviceObjectPointer(pustrDeviceName,
257  &pFileObject,
258  &pDeviceObject);
259  if (!NT_SUCCESS(Status))
260  {
261  ERR("Could not open device %wZ, 0x%lx\n", pustrDeviceName, Status);
262  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
263  return NULL;
264  }
265 
266  /* Copy the device and file object pointers */
267  pGraphicsDevice->DeviceObject = pDeviceObject;
268  pGraphicsDevice->FileObject = pFileObject;
269 
270  /* Initialize and register the device with videoprt for Win32k callbacks */
271  Win32kCallbacks.PhysDisp = pGraphicsDevice;
272  Win32kCallbacks.Callout = VideoPortCallout;
273  // Reset the data being returned prior to the call.
274  Win32kCallbacks.bACPI = FALSE;
275  Win32kCallbacks.pPhysDeviceObject = NULL;
276  Win32kCallbacks.DualviewFlags = 0;
277  Status = (NTSTATUS)EngDeviceIoControl((HANDLE)pDeviceObject,
279  &Win32kCallbacks,
280  sizeof(Win32kCallbacks),
281  &Win32kCallbacks,
282  sizeof(Win32kCallbacks),
283  &ulReturn);
284  if (Status != ERROR_SUCCESS)
285  {
286  ERR("EngDeviceIoControl(0x%p, IOCTL_VIDEO_INIT_WIN32K_CALLBACKS) failed, Status 0x%lx\n",
288  }
289  // TODO: Set flags according to the results.
290  // if (Win32kCallbacks.bACPI)
291  // if (Win32kCallbacks.DualviewFlags & ???)
292  // Win32kCallbacks.pPhysDeviceObject;
293 
294  /* Copy the device name */
295  RtlStringCbCopyNW(pGraphicsDevice->szNtDeviceName,
296  sizeof(pGraphicsDevice->szNtDeviceName),
297  pustrDeviceName->Buffer,
298  pustrDeviceName->Length);
299 
300  /* Create a Win32 device name (FIXME: virtual devices!) */
301  RtlStringCbPrintfW(pGraphicsDevice->szWinDeviceName,
302  sizeof(pGraphicsDevice->szWinDeviceName),
303  L"\\\\.\\DISPLAY%d",
304  (int)giDevNum);
305 
306  /* Allocate a buffer for the strings */
307  cj = pustrDiplayDrivers->Length + pustrDescription->Length + sizeof(WCHAR);
309  if (!pwsz)
310  {
311  ERR("Could not allocate string buffer\n");
312  ASSERT(FALSE); // FIXME
313  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
314  return NULL;
315  }
316 
317  /* Copy the display driver names */
318  pGraphicsDevice->pDiplayDrivers = pwsz;
319  RtlCopyMemory(pGraphicsDevice->pDiplayDrivers,
320  pustrDiplayDrivers->Buffer,
321  pustrDiplayDrivers->Length);
322 
323  /* Copy the description */
324  pGraphicsDevice->pwszDescription = pwsz + pustrDiplayDrivers->Length / sizeof(WCHAR);
325  RtlCopyMemory(pGraphicsDevice->pwszDescription,
326  pustrDescription->Buffer,
327  pustrDescription->Length);
328  pGraphicsDevice->pwszDescription[pustrDescription->Length/sizeof(WCHAR)] = 0;
329 
330  /* Initialize the pdevmodeInfo list and default index */
331  pGraphicsDevice->pdevmodeInfo = NULL;
332  pGraphicsDevice->iDefaultMode = 0;
333  pGraphicsDevice->iCurrentMode = 0;
334 
335  // FIXME: initialize state flags
336  pGraphicsDevice->StateFlags = 0;
337 
338  /* Create the mode list */
339  pGraphicsDevice->pDevModeList = NULL;
340  if (!EngpPopulateDeviceModeList(pGraphicsDevice, pdmDefault))
341  {
342  ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
343  return NULL;
344  }
345 
346  /* Lock loader */
348 
349  /* Insert the device into the global list */
350  pGraphicsDevice->pNextGraphicsDevice = NULL;
352  gpGraphicsDeviceLast->pNextGraphicsDevice = pGraphicsDevice;
353  gpGraphicsDeviceLast = pGraphicsDevice;
355  gpGraphicsDeviceFirst = pGraphicsDevice;
356 
357  /* Increment the device number */
358  giDevNum++;
359 
360  /* Unlock loader */
362  TRACE("Prepared %lu modes for %ls\n", pGraphicsDevice->cDevModes, pGraphicsDevice->pwszDescription);
363 
364  return pGraphicsDevice;
365 }
BOOLEAN EngpPopulateDeviceModeList(_Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault)
Definition: device.c:36
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_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:54
DWORD StateFlags
Definition: pdevobj.h:66
LONG NTSTATUS
Definition: precomp.h:26
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:262
#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:167
static PGRAPHICS_DEVICE gpGraphicsDeviceFirst
Definition: device.c:18
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)
smooth NULL
Definition: ftsmooth.c:416
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define TRACE(s)
Definition: solgame.cpp:4
struct _GRAPHICS_DEVICE * pNextGraphicsDevice
Definition: pdevobj.h:61
__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:264
static HSEMAPHORE ghsemGraphicsDeviceList
Definition: device.c:20
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
#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:265
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
static ULONG giDevNum
Definition: device.c:21
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
PDEVMODEINFO pdevmodeInfo
Definition: pdevobj.h:68
ULONG iDefaultMode
Definition: pdevobj.h:77
PFILE_OBJECT FileObject
Definition: pdevobj.h:75

Referenced by InitDisplayDriver().

◆ InitDeviceImpl()

INIT_FUNCTION 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
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DriverEntry().

◆ UserRefreshDisplay()

VOID UserRefreshDisplay ( IN PPDEVOBJ  ppdev)

Definition at line 289 of file display.c.

290 {
291  ULONG_PTR ulResult;
292  // PVOID pvOldCursor;
293 
294  // TODO: Re-enable the cursor reset code once this function becomes called
295  // from within a Win32 thread... Indeed UserSetCursor() requires this, but
296  // at the moment this function is directly called from a separate thread
297  // from within videoprt, instead of by a separate win32k system thread.
298 
299  if (!ppdev)
300  return;
301 
302  PDEVOBJ_vReference(ppdev);
303 
304  /* Remove mouse pointer */
305  // pvOldCursor = UserSetCursor(NULL, TRUE);
306 
307  /* Do the mode switch -- Use the actual same current mode */
308  ulResult = PDEVOBJ_bSwitchMode(ppdev, ppdev->pdmwDev);
309  ASSERT(ulResult);
310 
311  /* Restore mouse pointer, no hooks called */
312  // pvOldCursor = UserSetCursor(pvOldCursor, TRUE);
313  // ASSERT(pvOldCursor == NULL);
314 
315  /* Update the system metrics */
316  InitMetrics();
317 
318  /* Set new size of the monitor */
319  // UserUpdateMonitorSize((HDEV)ppdev);
320 
321  //co_IntShowDesktop(pdesk, ppdev->gdiinfo.ulHorzRes, ppdev->gdiinfo.ulVertRes);
323 
324  PDEVOBJ_vRelease(ppdev);
325 }
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:63
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().

◆ VideoPortCallout()

VOID NTAPI VideoPortCallout ( _In_ PVOID  Params)

Definition at line 167 of file device.c.

169 {
170 /*
171  * IMPORTANT NOTICE!! On Windows XP/2003 this function triggers the creation of
172  * a specific VideoPortCalloutThread() system thread using the same mechanism
173  * as the RIT/desktop/Ghost system threads.
174  */
175 
177 
178  TRACE("VideoPortCallout(0x%p, 0x%x)\n",
179  CallbackParams, CallbackParams ? CallbackParams->CalloutType : -1);
180 
181  if (!CallbackParams)
182  return;
183 
184  switch (CallbackParams->CalloutType)
185  {
187  {
188  TRACE("VideoPortCallout: VideoFindAdapterCallout called - Param = %s\n",
189  CallbackParams->Param ? "TRUE" : "FALSE");
190  if (CallbackParams->Param == TRUE)
191  {
192  /* Re-enable the display */
194  }
195  else
196  {
197  /* Disable the display */
198  NOTHING; // Nothing to do for the moment...
199  }
200 
201  CallbackParams->Status = STATUS_SUCCESS;
202  break;
203  }
204 
208  case VideoWakeupCallout:
214  ERR("VideoPortCallout: CalloutType 0x%x is UNIMPLEMENTED!\n", CallbackParams->CalloutType);
215  CallbackParams->Status = STATUS_NOT_IMPLEMENTED;
216  break;
217 
218  default:
219  ERR("VideoPortCallout: Unknown CalloutType 0x%x\n", CallbackParams->CalloutType);
220  CallbackParams->Status = STATUS_UNSUCCESSFUL;
221  break;
222  }
223 }
#define TRUE
Definition: types.h:120
VIDEO_WIN32K_CALLBACKS_PARAMS_TYPE CalloutType
Definition: ntddvdeo.h:249
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
PPDEVOBJ gppdevPrimary
Definition: pdevobj.c:13
VOID UserRefreshDisplay(IN PPDEVOBJ ppdev)
Definition: display.c:289
#define TRACE(s)
Definition: solgame.cpp:4
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
struct _VIDEO_WIN32K_CALLBACKS_PARAMS * PVIDEO_WIN32K_CALLBACKS_PARAMS
#define NOTHING
Definition: env_spec_w32.h:461
#define ERR(fmt,...)
Definition: debug.h:109
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by EngpRegisterGraphicsDevice().

Variable Documentation

◆ dwIoControlCode

_In_ DWORD dwIoControlCode

Definition at line 497 of file device.c.

Referenced by _In_reads_(), and _Success_().

◆ ghsemGraphicsDeviceList

HSEMAPHORE ghsemGraphicsDeviceList
static

Definition at line 20 of file device.c.

Referenced by EngpFindGraphicsDevice(), EngpRegisterGraphicsDevice(), and InitDeviceImpl().

◆ giDevNum

ULONG giDevNum = 1
static

Definition at line 21 of file device.c.

Referenced by EngpRegisterGraphicsDevice().

◆ gpGraphicsDeviceFirst

PGRAPHICS_DEVICE gpGraphicsDeviceFirst = NULL
static

Definition at line 18 of file device.c.

Referenced by EngpFindGraphicsDevice(), and EngpRegisterGraphicsDevice().

◆ gpGraphicsDeviceLast

PGRAPHICS_DEVICE gpGraphicsDeviceLast = NULL
static

Definition at line 19 of file device.c.

Referenced by EngpRegisterGraphicsDevice().

◆ gpPrimaryGraphicsDevice

PGRAPHICS_DEVICE gpPrimaryGraphicsDevice

Definition at line 15 of file device.c.

Referenced by EngpCreatePDEV(), and InitVideo().

◆ gpVgaGraphicsDevice

PGRAPHICS_DEVICE gpVgaGraphicsDevice

Definition at line 16 of file device.c.

Referenced by InitVideo().