ReactOS 0.4.16-dev-2293-g4d8327b
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)
 
NTSTATUS NTAPI EngpUpdateMonitorDevices (_In_ PGRAPHICS_DEVICE pGraphicsDevice)
 
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice (_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum)
 
PGRAPHICS_DEVICE NTAPI EngpRegisterGraphicsDevice (_In_ PUNICODE_STRING pustrDeviceName, _In_ PUNICODE_STRING pustrDiplayDrivers, _In_ PUNICODE_STRING pustrDescription)
 
NTSTATUS EngpUpdateGraphicsDeviceList (VOID)
 
NTSTATUS EngpGetDisplayDriverParameters (_In_ PGRAPHICS_DEVICE pGraphicsDevice, _Out_ PDEVMODEW pdm)
 
DWORD EngpGetDisplayDriverAccelerationLevel (_In_ PGRAPHICS_DEVICE pGraphicsDevice)
 
NTSTATUS NTAPI InitDeviceImpl (VOID)
 

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

913{
915
916 status = EngpFileIoRequest(pFileObject,
918 lpBuffer,
919 nLength,
920 0,
921 lpBytesWritten);
922 if (!NT_SUCCESS(status))
923 {
924 *lpBytesWritten = 0;
925 }
926}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
_Out_ LPWSTR lpBuffer
Definition: netsh.h:68
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
Definition: ps.c:97
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:850
WINBASEAPI _In_ DWORD nLength
Definition: wincon.h:682

◆ EngpFindGraphicsDevice()

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

Definition at line 795 of file device.c.

798{
799 UNICODE_STRING ustrCurrent;
800 PGRAPHICS_DEVICE pGraphicsDevice;
801 ULONG i;
802 TRACE("EngpFindGraphicsDevice('%wZ', %lu)\n",
803 pustrDevice, iDevNum);
804
805 /* Lock list */
807
808 if (pustrDevice && pustrDevice->Buffer)
809 {
810 /* Find specified video adapter by name */
811 for (pGraphicsDevice = gpGraphicsDeviceFirst;
812 pGraphicsDevice;
813 pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice)
814 {
815 /* Compare the device name */
816 RtlInitUnicodeString(&ustrCurrent, pGraphicsDevice->szWinDeviceName);
817 if (RtlEqualUnicodeString(&ustrCurrent, pustrDevice, FALSE))
818 {
819 break;
820 }
821 }
822
823 if (pGraphicsDevice)
824 {
825 /* Validate selected monitor number */
826#if 0
827 if (iDevNum >= pGraphicsDevice->dwMonCnt)
828 pGraphicsDevice = NULL;
829#else
830 /* FIXME: dwMonCnt not initialized, see EngpRegisterGraphicsDevice */
831#endif
832 }
833 }
834 else
835 {
836 /* Select video adapter by device number */
837 for (pGraphicsDevice = gpGraphicsDeviceFirst, i = 0;
838 pGraphicsDevice && i < iDevNum;
839 pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice, i++);
840 }
841
842 /* Unlock list */
844
845 return pGraphicsDevice;
846}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
VOID WINAPI EngReleaseSemaphore(IN HSEMAPHORE hsem)
Definition: eng.c:235
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
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define TRACE(s)
Definition: solgame.cpp:4
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
DWORD dwMonCnt
Definition: pdevobj.h:73
struct _GRAPHICS_DEVICE * pNextGraphicsDevice
Definition: pdevobj.h:61
uint32_t ULONG
Definition: typedefs.h:59
static PGRAPHICS_DEVICE gpGraphicsDeviceFirst
Definition: device.c:18
static HSEMAPHORE ghsemGraphicsDeviceList
Definition: device.c:20
ENGAPI VOID APIENTRY EngAcquireSemaphore(_Inout_ HSEMAPHORE hsem)

Referenced by co_IntInitializeDesktopGraphics(), EngpUpdateGraphicsDeviceList(), MDEVOBJ_Create(), PDEVOBJ_lChangeDisplaySettings(), UserEnumDisplayDevices(), and UserEnumDisplaySettings().

◆ EngpGetDisplayDriverAccelerationLevel()

DWORD EngpGetDisplayDriverAccelerationLevel ( _In_ PGRAPHICS_DEVICE  pGraphicsDevice)

Definition at line 420 of file device.c.

422{
423 HKEY hKey;
424 DWORD dwAccelerationLevel = 0;
425 RTL_QUERY_REGISTRY_TABLE DisplaySettingsTable[] =
426 {
427 {
428 NULL,
430 L"Acceleration.Level",
431 &dwAccelerationLevel,
432 REG_NONE, NULL, 0
433 },
434 {0}
435 };
436
437 hKey = EngpGetRegistryHandleFromDeviceMap(pGraphicsDevice);
438 if (!hKey)
439 return 0;
440
442 (PWSTR)hKey,
443 DisplaySettingsTable,
444 NULL,
445 NULL);
446 ZwClose(hKey);
447
448 return dwAccelerationLevel;
449}
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define REG_NONE
Definition: nt_native.h:1495
#define RTL_REGISTRY_HANDLE
Definition: nt_native.h:168
uint16_t * PWSTR
Definition: typedefs.h:56
static HKEY EngpGetRegistryHandleFromDeviceMap(_In_ PGRAPHICS_DEVICE pGraphicsDevice)
Definition: device.c:336

Referenced by MDEVOBJ_Create().

◆ EngpGetDisplayDriverParameters()

NTSTATUS EngpGetDisplayDriverParameters ( _In_ PGRAPHICS_DEVICE  pGraphicsDevice,
_Out_ PDEVMODEW  pdm 
)

Definition at line 374 of file device.c.

377{
378 HKEY hKey;
380 RTL_QUERY_REGISTRY_TABLE DisplaySettingsTable[] =
381 {
382#define READ(field, str) \
383 { \
384 NULL, \
385 RTL_QUERY_REGISTRY_DIRECT, \
386 L ##str, \
387 &pdm->field, \
388 REG_NONE, NULL, 0 \
389 },
390 READ(dmBitsPerPel, "DefaultSettings.BitsPerPel")
391 READ(dmPelsWidth, "DefaultSettings.XResolution")
392 READ(dmPelsHeight, "DefaultSettings.YResolution")
393 READ(dmDisplayFlags, "DefaultSettings.Flags")
394 READ(dmDisplayFrequency, "DefaultSettings.VRefresh")
395 READ(dmPanningWidth, "DefaultSettings.XPanning")
396 READ(dmPanningHeight, "DefaultSettings.YPanning")
397 READ(dmDisplayOrientation, "DefaultSettings.Orientation")
398 READ(dmDisplayFixedOutput, "DefaultSettings.FixedOutput")
399 READ(dmPosition.x, "Attach.RelativeX")
400 READ(dmPosition.y, "Attach.RelativeY")
401#undef READ
402 {0}
403 };
404
405 hKey = EngpGetRegistryHandleFromDeviceMap(pGraphicsDevice);
406 if (!hKey)
407 return STATUS_UNSUCCESSFUL;
408
410 (PWSTR)hKey,
411 DisplaySettingsTable,
412 NULL,
413 NULL);
414
415 ZwClose(hKey);
416 return Status;
417}
Status
Definition: gdiplustypes.h:25
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define READ(field, str)
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by LDEVOBJ_bProbeAndCaptureDevmode().

◆ EngpRegisterGraphicsDevice()

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

Definition at line 662 of file device.c.

666{
667 PGRAPHICS_DEVICE pGraphicsDevice;
669 PFILE_OBJECT pFileObject;
671 VIDEO_WIN32K_CALLBACKS Win32kCallbacks;
672 ULONG ulReturn;
673 PWSTR pwsz;
674 ULONG cj;
675
676 TRACE("EngpRegisterGraphicsDevice(%wZ)\n", pustrDeviceName);
677
678 /* Allocate a GRAPHICS_DEVICE structure */
679 pGraphicsDevice = ExAllocatePoolZero(PagedPool,
680 sizeof(GRAPHICS_DEVICE),
682 if (!pGraphicsDevice)
683 {
684 ERR("ExAllocatePoolWithTag failed\n");
685 return NULL;
686 }
687
688 /* Try to open and enable the device */
689 Status = IoGetDeviceObjectPointer(pustrDeviceName,
691 &pFileObject,
693 if (!NT_SUCCESS(Status))
694 {
695 ERR("Could not open device %wZ, 0x%lx\n", pustrDeviceName, Status);
696 ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
697 return NULL;
698 }
699
700 /* Copy the device and file object pointers */
701 pGraphicsDevice->DeviceObject = pDeviceObject;
702 pGraphicsDevice->FileObject = pFileObject;
703
704 /* Initialize and register the device with videoprt for Win32k callbacks */
705 Win32kCallbacks.PhysDisp = pGraphicsDevice;
706 Win32kCallbacks.Callout = VideoPortCallout;
707 // Reset the data being returned prior to the call.
708 Win32kCallbacks.bACPI = FALSE;
709 Win32kCallbacks.pPhysDeviceObject = NULL;
710 Win32kCallbacks.DualviewFlags = 0;
711 Status = (NTSTATUS)EngDeviceIoControl((HANDLE)pDeviceObject,
713 &Win32kCallbacks,
714 sizeof(Win32kCallbacks),
715 &Win32kCallbacks,
716 sizeof(Win32kCallbacks),
717 &ulReturn);
718 if (Status != ERROR_SUCCESS)
719 {
720 ERR("EngDeviceIoControl(0x%p, IOCTL_VIDEO_INIT_WIN32K_CALLBACKS) failed, Status 0x%lx\n",
722 }
723 // TODO: Set flags according to the results.
724 // if (Win32kCallbacks.bACPI)
725 // if (Win32kCallbacks.DualviewFlags & ???)
726 pGraphicsDevice->PhysDeviceHandle = Win32kCallbacks.pPhysDeviceObject;
727
728 /* Copy the device name */
729 RtlStringCbCopyNW(pGraphicsDevice->szNtDeviceName,
730 sizeof(pGraphicsDevice->szNtDeviceName),
731 pustrDeviceName->Buffer,
732 pustrDeviceName->Length);
733
734 /* Create a Win32 device name (FIXME: virtual devices!) */
735 RtlStringCbPrintfW(pGraphicsDevice->szWinDeviceName,
736 sizeof(pGraphicsDevice->szWinDeviceName),
737 L"\\\\.\\DISPLAY%d",
738 (int)giDevNum);
739
740 /* Allocate a buffer for the strings */
741 cj = pustrDiplayDrivers->Length + pustrDescription->Length + sizeof(WCHAR);
743 if (!pwsz)
744 {
745 ERR("Could not allocate string buffer\n");
746 ASSERT(FALSE); // FIXME
747 ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
748 return NULL;
749 }
750
751 /* Copy the display driver names */
752 pGraphicsDevice->pDiplayDrivers = pwsz;
753 RtlCopyMemory(pGraphicsDevice->pDiplayDrivers,
754 pustrDiplayDrivers->Buffer,
755 pustrDiplayDrivers->Length);
756
757 /* Copy the description */
758 pGraphicsDevice->pwszDescription = pwsz + pustrDiplayDrivers->Length / sizeof(WCHAR);
759 RtlCopyMemory(pGraphicsDevice->pwszDescription,
760 pustrDescription->Buffer,
761 pustrDescription->Length);
762 pGraphicsDevice->pwszDescription[pustrDescription->Length/sizeof(WCHAR)] = 0;
763
764 /* Update list of connected monitors */
765 EngpUpdateMonitorDevices(pGraphicsDevice);
766
767 /* Lock loader */
769
770 /* Insert the device into the global list */
771 EngpLinkGraphicsDevice(pGraphicsDevice);
772
773 /* Increment the device number */
774 giDevNum++;
775
776 /* Unlock loader */
778
779 /* HACK: already in graphic mode; display wallpaper on this new display */
781 {
782 UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY");
783 UNICODE_STRING DisplayName;
784 HDC hdc;
785 RtlInitUnicodeString(&DisplayName, pGraphicsDevice->szWinDeviceName);
786 hdc = IntGdiCreateDC(&DriverName, &DisplayName, NULL, NULL, FALSE);
788 }
789
790 return pGraphicsDevice;
791}
#define ERR(fmt,...)
Definition: precomp.h:57
HDC FASTCALL IntGdiCreateDC(PUNICODE_STRING Driver, PUNICODE_STRING pustrDevice, PVOID pUMdhpdev, CONST PDEVMODEW pdmInit, BOOL CreateAsIC)
Definition: dclife.c:1040
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NTSTATUS
Definition: precomp.h:19
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
HDC hdc
Definition: main.c:9
FORCEINLINE PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
static HDC
Definition: imagelist.c:88
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_READ_DATA
Definition: nt_native.h:628
#define IOCTL_VIDEO_INIT_WIN32K_CALLBACKS
Definition: ntddvdeo.h:131
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
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
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 pDiplayDrivers
Definition: pdevobj.h:71
PFILE_OBJECT FileObject
Definition: pdevobj.h:75
WCHAR szNtDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:59
LPWSTR pwszDescription
Definition: pdevobj.h:72
PDEVICE_OBJECT DeviceObject
Definition: pdevobj.h:63
PDEVICE_OBJECT PhysDeviceHandle
Definition: pdevobj.h:64
OUT ULONG DualviewFlags
Definition: ntddvdeo.h:335
IN PVIDEO_WIN32K_CALLOUT Callout
Definition: ntddvdeo.h:332
OUT HANDLE pPhysDeviceObject
Definition: ntddvdeo.h:334
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
static ULONG giDevNum
Definition: device.c:21
VOID NTAPI VideoPortCallout(_In_ PVOID Params)
Definition: device.c:457
NTSTATUS NTAPI EngpUpdateMonitorDevices(_In_ PGRAPHICS_DEVICE pGraphicsDevice)
Definition: device.c:568
HDC ScreenDeviceContext
Definition: desktop.c:53
BOOL FASTCALL IntPaintDesktop(HDC hDC)
Definition: desktop.c:1851
#define GDITAG_DRVSUP
Definition: tags.h:77
#define GDITAG_GDEVICE
Definition: tags.h:99
_In_ ULONG cj
Definition: winddi.h:3540
* PFILE_OBJECT
Definition: iotypes.h:1998
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by InitDisplayDriver().

◆ EngpUpdateGraphicsDeviceList()

NTSTATUS EngpUpdateGraphicsDeviceList ( VOID  )

Definition at line 182 of file device.c.

183{
184 ULONG iDevNum, ulMaxObjectNumber = 0;
185 WCHAR awcDeviceName[20], awcWinDeviceName[20];
186 UNICODE_STRING ustrDeviceName;
187 WCHAR awcBuffer[256];
189 PGRAPHICS_DEVICE pGraphicsDevice, pNewPrimaryGraphicsDevice = NULL;
190 ULONG cbValue;
191 HKEY hkey;
192
193 /* Open the key for the adapters */
194 Status = RegOpenKey(L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO", &hkey);
195 if (!NT_SUCCESS(Status))
196 {
197 ERR("Could not open HARDWARE\\DEVICEMAP\\VIDEO registry key:0x%lx\n", Status);
198 return Status;
199 }
200
201 /* Get the maximum number of adapters */
202 if (!RegReadDWORD(hkey, L"MaxObjectNumber", &ulMaxObjectNumber))
203 {
204 ERR("Could not read MaxObjectNumber, defaulting to 0.\n");
205 }
206
207 TRACE("Found %lu devices\n", ulMaxObjectNumber + 1);
208
209 /* Loop through all adapters, to detect new ones */
210 for (iDevNum = 0; iDevNum <= ulMaxObjectNumber; iDevNum++)
211 {
212 /* Create the adapter's key name */
213 swprintf(awcDeviceName, L"\\Device\\Video%lu", iDevNum);
214
215 /* Create the display device name */
216 swprintf(awcWinDeviceName, L"\\\\.\\DISPLAY%lu", iDevNum + 1);
217 RtlInitUnicodeString(&ustrDeviceName, awcWinDeviceName);
218
219 /* Check if the device exists already */
220 pGraphicsDevice = EngpFindGraphicsDevice(&ustrDeviceName, iDevNum);
221 if (pGraphicsDevice != NULL)
222 {
223 continue;
224 }
225
226 /* Read the reg key name */
227 cbValue = sizeof(awcBuffer);
228 Status = RegQueryValue(hkey, awcDeviceName, REG_SZ, awcBuffer, &cbValue);
229 if (!NT_SUCCESS(Status))
230 {
231 ERR("failed to query the registry path:0x%lx\n", Status);
232 continue;
233 }
234
235 /* Initialize the driver for this device */
236 pGraphicsDevice = InitDisplayDriver(awcDeviceName, awcBuffer);
237 if (!pGraphicsDevice) continue;
238 }
239
240 /* Close the device map registry key */
241 ZwClose(hkey);
242
243 /* Choose a VGA device */
244 /* Try a device with DISPLAY_DEVICE_VGA_COMPATIBLE flag. If not found,
245 * fall back to current VGA device */
246 for (pGraphicsDevice = gpGraphicsDeviceFirst;
247 pGraphicsDevice;
248 pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice)
249 {
250 if (pGraphicsDevice == gpVgaGraphicsDevice)
251 continue;
252 if (pGraphicsDevice->StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE && EngpHasVgaDriver(pGraphicsDevice))
253 {
254 gpVgaGraphicsDevice = pGraphicsDevice;
255 break;
256 }
257 }
258
259 /* Handle gbBaseVideo */
260 if (gbBaseVideo)
261 {
262 PGRAPHICS_DEVICE pToDelete;
263
264 /* Lock list */
266
267 /* Remove every device from linked list, except base-video one */
268 pGraphicsDevice = gpGraphicsDeviceFirst;
269 while (pGraphicsDevice)
270 {
271 if (!EngpHasVgaDriver(pGraphicsDevice))
272 {
273 /* Not base-video device. Remove it */
274 pToDelete = pGraphicsDevice;
275 TRACE("Removing non-base-video device %S (%S)\n", pToDelete->szWinDeviceName, pToDelete->szNtDeviceName);
276
277 EngpUnlinkGraphicsDevice(pGraphicsDevice);
278 pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice;
279
280 /* Free memory */
283 }
284 else
285 {
286 pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice;
287 }
288 }
289
290 /* Unlock list */
292 }
293
294 /* Choose a primary device (if none already exists) */
296 {
297 for (pGraphicsDevice = gpGraphicsDeviceFirst;
298 pGraphicsDevice;
299 pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice)
300 {
301 if (!EngpHasVgaDriver(pGraphicsDevice))
302 {
303 pNewPrimaryGraphicsDevice = pGraphicsDevice;
304 break;
305 }
306 }
307 if (!pNewPrimaryGraphicsDevice)
308 pNewPrimaryGraphicsDevice = gpGraphicsDeviceFirst;
309 if (pNewPrimaryGraphicsDevice)
310 {
311 pNewPrimaryGraphicsDevice->StateFlags |= DISPLAY_DEVICE_PRIMARY_DEVICE;
312 gpPrimaryGraphicsDevice = pNewPrimaryGraphicsDevice;
313 }
314 }
315
316 /* Can we link VGA device to primary device? */
321 {
322 /* Yes. Remove VGA device from global list, and attach it to primary device */
323 TRACE("Linking VGA device %S to primary device %S\n", gpVgaGraphicsDevice->szNtDeviceName, gpPrimaryGraphicsDevice->szNtDeviceName);
325 EngpUnlinkGraphicsDevice(gpVgaGraphicsDevice);
328 }
329
330 return STATUS_SUCCESS;
331}
#define swprintf
Definition: precomp.h:40
#define REG_SZ
Definition: layer.c:22
#define STATUS_SUCCESS
Definition: shellext.h:65
DWORD StateFlags
Definition: pdevobj.h:66
struct _GRAPHICS_DEVICE * pVgaDevice
Definition: pdevobj.h:62
static BOOLEAN EngpHasVgaDriver(_In_ PGRAPHICS_DEVICE pGraphicsDevice)
Definition: device.c:37
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum)
Definition: device.c:795
static PGRAPHICS_DEVICE gpPrimaryGraphicsDevice
Definition: device.c:15
static PGRAPHICS_DEVICE gpVgaGraphicsDevice
Definition: device.c:16
BOOL NTAPI RegReadDWORD(HKEY hkey, PCWSTR pwszValue, PDWORD pdwData)
Definition: registry.c:149
BOOL gbBaseVideo
Definition: display.c:12
PGRAPHICS_DEVICE NTAPI InitDisplayDriver(IN PWSTR pwszDeviceName, IN PWSTR pwszRegKey)
Definition: display.c:66
#define DISPLAY_DEVICE_VGA_COMPATIBLE
Definition: wingdi.h:1400
#define DISPLAY_DEVICE_PRIMARY_DEVICE
Definition: wingdi.h:1398
#define RegOpenKey
Definition: winreg.h:526
#define RegQueryValue
Definition: winreg.h:530

Referenced by co_IntInitializeDesktopGraphics(), InitVideo(), and UserEnumDisplayDevices().

◆ EngpUpdateMonitorDevices()

NTSTATUS NTAPI EngpUpdateMonitorDevices ( _In_ PGRAPHICS_DEVICE  pGraphicsDevice)

Definition at line 568 of file device.c.

570{
571 PDEVICE_RELATIONS pDeviceRelations;
572 PVIDEO_MONITOR_DEVICE pMonitorDevices;
573 ULONG i, bytesWritten, monitorCount;
575 HANDLE hkRegistry;
576
577 /* Request right PDO for device relations */
578 Status = EngpPnPTargetRelationRequest(pGraphicsDevice->DeviceObject, &pDeviceRelations);
579 if (!NT_SUCCESS(Status))
580 {
581 ERR("EngpPnPTargetRelationRequest() failed with status 0x%08x\n", Status);
582 return Status;
583 }
584 ASSERT(pDeviceRelations->Count == 1);
585
586 /* Invalidate relations, so that videoprt reenumerates its monitors.
587 * Only do this for valid PDOs - check by trying to open registry key. */
588 Status = IoOpenDeviceRegistryKey(pDeviceRelations->Objects[0],
590 KEY_READ,
591 &hkRegistry);
592 if (NT_SUCCESS(Status))
593 {
594 ZwClose(hkRegistry);
596 }
597 else
598 {
599 /* Legacy device without valid PDO - skip invalidation.
600 * This is expected for non-PnP devices like VGA. */
601 }
602
603 /* Free returned structure */
604 for (i = 0; i < pDeviceRelations->Count; i++)
605 ObDereferenceObject(pDeviceRelations->Objects[i]);
606 ExFreePool(pDeviceRelations);
607
608 /* Now, get list of monitor PDOs */
609 Status = EngDeviceIoControl(pGraphicsDevice->DeviceObject,
611 NULL, 0,
612 &pMonitorDevices, sizeof(pMonitorDevices),
613 &bytesWritten);
614 if (Status != ERROR_SUCCESS)
615 {
616 ERR("EngDeviceIoControl(IOCTL_VIDEO_ENUM_MONITOR_PDO) failed with status 0x%08x\n", Status);
617 return Status;
618 }
619 ASSERT(bytesWritten == sizeof(pMonitorDevices));
620
621 /* Count number of available monitors */
622 for (monitorCount = 0; pMonitorDevices[monitorCount].pdo; ++monitorCount)
623 ;
624
625 if (pGraphicsDevice->pvMonDev)
626 {
627 /* Erase everything */
628 for (i = 0; i < pGraphicsDevice->dwMonCnt; i++)
629 ObDereferenceObject(pGraphicsDevice->pvMonDev[i].pdo);
630 ExFreePoolWithTag(pGraphicsDevice->pvMonDev, GDITAG_GDEVICE);
631 pGraphicsDevice->pvMonDev = NULL;
632 pGraphicsDevice->dwMonCnt = 0;
633 }
634
635 if (monitorCount > 0)
636 {
637 pGraphicsDevice->pvMonDev = ExAllocatePoolZero(PagedPool,
638 monitorCount * sizeof(VIDEO_MONITOR_DEVICE),
640 if (!pGraphicsDevice->pvMonDev)
641 {
642 for (i = 0; pMonitorDevices[i].pdo; ++i)
643 ObDereferenceObject(pMonitorDevices[i].pdo);
644 ExFreePool(pMonitorDevices);
646 }
647
648 /* Copy data */
649 for (i = 0; i < monitorCount; i++)
650 {
651 TRACE("%S\\Monitor%u: PDO %p HwID %u\n", pGraphicsDevice->szWinDeviceName, i, pMonitorDevices[i].pdo, pMonitorDevices[i].HwID);
652 pGraphicsDevice->pvMonDev[pGraphicsDevice->dwMonCnt++] = pMonitorDevices[i];
653 }
654 }
655
656 ExFreePool(pMonitorDevices);
657 return STATUS_SUCCESS;
658}
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
GLenum GLsizei GLuint GLint * bytesWritten
Definition: glext.h:11123
#define KEY_READ
Definition: nt_native.h:1026
#define IOCTL_VIDEO_ENUM_MONITOR_PDO
Definition: ntddvdeo.h:128
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:1621
NTSTATUS NTAPI IoSynchronousInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:1798
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2165
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
static NTSTATUS EngpPnPTargetRelationRequest(_In_ PDEVICE_OBJECT pDeviceObject, _Out_ PDEVICE_RELATIONS *pDeviceRelations)
Definition: device.c:520
@ BusRelations
Definition: iotypes.h:2154
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by EngpRegisterGraphicsDevice(), and UserEnumDisplayDevices().

◆ InitDeviceImpl()

NTSTATUS NTAPI InitDeviceImpl ( VOID  )

Definition at line 26 of file device.c.

27{
31
32 return STATUS_SUCCESS;
33}
HSEMAPHORE WINAPI EngCreateSemaphore(VOID)
Definition: eng.c:75

Referenced by DriverEntry().

◆ PDEVOBJ_vRefreshModeList()

VOID NTAPI PDEVOBJ_vRefreshModeList ( PPDEVOBJ  ppdev)

Definition at line 432 of file pdevobj.c.

434{
435 PGRAPHICS_DEVICE pGraphicsDevice;
436 PDEVMODEINFO pdminfo, pdmiNext;
437
438 /* Lock the PDEV */
440
441 pGraphicsDevice = ppdev->pGraphicsDevice;
442
443 /* Clear out the modes */
444 for (pdminfo = pGraphicsDevice->pdevmodeInfo;
445 pdminfo;
446 pdminfo = pdmiNext)
447 {
448 pdmiNext = pdminfo->pdmiNext;
450 }
451 pGraphicsDevice->pdevmodeInfo = NULL;
453 pGraphicsDevice->pDevModeList = NULL;
454
455 /* Update available display mode list */
456 LDEVOBJ_bBuildDevmodeList(pGraphicsDevice);
457
458 /* Unlock PDEV */
460}
BOOL LDEVOBJ_bBuildDevmodeList(_Inout_ PGRAPHICS_DEVICE pGraphicsDevice)
Definition: ldevobj.c:565
struct _DEVMODEINFO * pdmiNext
Definition: pdevobj.h:44
PDEVMODEENTRY pDevModeList
Definition: pdevobj.h:70
PDEVMODEINFO pdevmodeInfo
Definition: pdevobj.h:68
PGRAPHICS_DEVICE pGraphicsDevice
Definition: pdevobj.h:127
HSEMAPHORE hsemDevLock
Definition: pdevobj.h:89
#define GDITAG_DEVMODE
Definition: tags.h:73

Referenced by UserEnumDisplaySettings().