https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6739fb1bc34249386d09d3...
commit 6739fb1bc34249386d09d36058b7ac0f1fc78a37 Author: Hervé Poussineau hpoussin@reactos.org AuthorDate: Sat Jun 19 17:07:13 2021 +0200 Commit: Hervé Poussineau hpoussin@reactos.org CommitDate: Sat Jul 10 16:27:44 2021 +0200
[WIN32K] Move detection of available display devices a new fonction EngpUpdateGraphicsDeviceList
- rewrite InitVideo() to call this new function - also call it at the start of UserEnumDisplayDevices, to detect new potential devices --- win32ss/gdi/eng/device.c | 78 +++++++++++++++++++++++++++++++++++++ win32ss/gdi/eng/device.h | 3 ++ win32ss/user/ntuser/display.c | 90 ++++--------------------------------------- win32ss/user/ntuser/ntuser.h | 6 +++ 4 files changed, 95 insertions(+), 82 deletions(-)
diff --git a/win32ss/gdi/eng/device.c b/win32ss/gdi/eng/device.c index d3503009c1a..a02ef9d3a32 100644 --- a/win32ss/gdi/eng/device.c +++ b/win32ss/gdi/eng/device.c @@ -32,6 +32,84 @@ InitDeviceImpl(VOID) return STATUS_SUCCESS; }
+NTSTATUS +EngpUpdateGraphicsDeviceList(VOID) +{ + ULONG iDevNum, iVGACompatible = -1, ulMaxObjectNumber = 0; + WCHAR awcDeviceName[20]; + WCHAR awcBuffer[256]; + NTSTATUS Status; + PGRAPHICS_DEVICE pGraphicsDevice; + ULONG cbValue; + HKEY hkey; + + /* Open the key for the adapters */ + Status = RegOpenKey(L"\Registry\Machine\HARDWARE\DEVICEMAP\VIDEO", &hkey); + if (!NT_SUCCESS(Status)) + { + ERR("Could not open HARDWARE\DEVICEMAP\VIDEO registry key:0x%lx\n", Status); + return Status; + } + + /* Read the name of the VGA adapter */ + cbValue = sizeof(awcDeviceName); + Status = RegQueryValue(hkey, L"VgaCompatible", REG_SZ, awcDeviceName, &cbValue); + if (NT_SUCCESS(Status)) + { + iVGACompatible = _wtoi(&awcDeviceName[sizeof("\Device\Video")-1]); + ERR("VGA adapter = %lu\n", iVGACompatible); + } + + /* Get the maximum mumber of adapters */ + if (!RegReadDWORD(hkey, L"MaxObjectNumber", &ulMaxObjectNumber)) + { + ERR("Could not read MaxObjectNumber, defaulting to 0.\n"); + } + + TRACE("Found %lu devices\n", ulMaxObjectNumber + 1); + + /* Loop through all adapters */ + for (iDevNum = 0; iDevNum <= ulMaxObjectNumber; iDevNum++) + { + /* Create the adapter's key name */ + swprintf(awcDeviceName, L"\Device\Video%lu", iDevNum); + + /* Read the reg key name */ + cbValue = sizeof(awcBuffer); + Status = RegQueryValue(hkey, awcDeviceName, REG_SZ, awcBuffer, &cbValue); + if (!NT_SUCCESS(Status)) + { + ERR("failed to query the registry path:0x%lx\n", Status); + continue; + } + + /* Initialize the driver for this device */ + pGraphicsDevice = InitDisplayDriver(awcDeviceName, awcBuffer); + if (!pGraphicsDevice) continue; + + /* Check if this is a VGA compatible adapter */ + if (pGraphicsDevice->StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE) + { + /* Save this as the VGA adapter */ + if (!gpVgaGraphicsDevice) + gpVgaGraphicsDevice = pGraphicsDevice; + TRACE("gpVgaGraphicsDevice = %p\n", gpVgaGraphicsDevice); + } + else + { + /* Set the first one as primary device */ + if (!gpPrimaryGraphicsDevice) + gpPrimaryGraphicsDevice = pGraphicsDevice; + TRACE("gpPrimaryGraphicsDevice = %p\n", gpPrimaryGraphicsDevice); + } + } + + /* Close the device map registry key */ + ZwClose(hkey); + + return STATUS_SUCCESS; +} + BOOLEAN EngpPopulateDeviceModeList( _Inout_ PGRAPHICS_DEVICE pGraphicsDevice, diff --git a/win32ss/gdi/eng/device.h b/win32ss/gdi/eng/device.h index b74649daa73..c66e4cf0ad6 100644 --- a/win32ss/gdi/eng/device.h +++ b/win32ss/gdi/eng/device.h @@ -39,6 +39,9 @@ EngpPopulateDeviceModeList( _Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault);
+NTSTATUS +EngpUpdateGraphicsDeviceList(VOID); + CODE_SEG("INIT") NTSTATUS NTAPI diff --git a/win32ss/user/ntuser/display.c b/win32ss/user/ntuser/display.c index 3c39c05ec35..676b7d0420c 100644 --- a/win32ss/user/ntuser/display.c +++ b/win32ss/user/ntuser/display.c @@ -155,12 +155,7 @@ NTSTATUS NTAPI InitVideo(VOID) { - ULONG iDevNum, iVGACompatible = -1, ulMaxObjectNumber = 0; - WCHAR awcDeviceName[20]; - WCHAR awcBuffer[256]; NTSTATUS Status; - PGRAPHICS_DEVICE pGraphicsDevice; - ULONG cbValue; HKEY hkey;
TRACE("----------------------------- InitVideo() -------------------------------\n"); @@ -173,85 +168,10 @@ InitVideo(VOID) if (gbBaseVideo) ERR("VGA mode requested.\n");
- /* Open the key for the adapters */ - Status = RegOpenKey(KEY_VIDEO, &hkey); + /* Initialize all display devices */ + Status = EngpUpdateGraphicsDeviceList(); if (!NT_SUCCESS(Status)) - { - ERR("Could not open HARDWARE\DEVICEMAP\VIDEO registry key:0x%lx\n", Status); return Status; - } - - /* Read the name of the VGA adapter */ - cbValue = sizeof(awcDeviceName); - Status = RegQueryValue(hkey, L"VgaCompatible", REG_SZ, awcDeviceName, &cbValue); - if (NT_SUCCESS(Status)) - { - iVGACompatible = _wtoi(&awcDeviceName[sizeof("\Device\Video")-1]); - ERR("VGA adapter = %lu\n", iVGACompatible); - } - - /* Get the maximum mumber of adapters */ - if (!RegReadDWORD(hkey, L"MaxObjectNumber", &ulMaxObjectNumber)) - { - ERR("Could not read MaxObjectNumber, defaulting to 0.\n"); - } - - TRACE("Found %lu devices\n", ulMaxObjectNumber + 1); - - /* Loop through all adapters */ - for (iDevNum = 0; iDevNum <= ulMaxObjectNumber; iDevNum++) - { - /* Create the adapter's key name */ - swprintf(awcDeviceName, L"\Device\Video%lu", iDevNum); - - /* Read the reg key name */ - cbValue = sizeof(awcBuffer); - Status = RegQueryValue(hkey, awcDeviceName, REG_SZ, awcBuffer, &cbValue); - if (!NT_SUCCESS(Status)) - { - ERR("failed to query the registry path:0x%lx\n", Status); - continue; - } - - /* Initialize the driver for this device */ - pGraphicsDevice = InitDisplayDriver(awcDeviceName, awcBuffer); - if (!pGraphicsDevice) continue; - - /* Check if this is a VGA compatible adapter */ - if (pGraphicsDevice->StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE) - { - /* Save this as the VGA adapter */ - if (!gpVgaGraphicsDevice) - gpVgaGraphicsDevice = pGraphicsDevice; - TRACE("gpVgaGraphicsDevice = %p\n", gpVgaGraphicsDevice); - } - else - { - /* Set the first one as primary device */ - if (!gpPrimaryGraphicsDevice) - gpPrimaryGraphicsDevice = pGraphicsDevice; - TRACE("gpPrimaryGraphicsDevice = %p\n", gpPrimaryGraphicsDevice); - } - } - - /* Close the device map registry key */ - ZwClose(hkey); - - /* Was VGA mode requested? */ - if (gbBaseVideo) - { - /* Check if we found a VGA compatible device */ - if (gpVgaGraphicsDevice) - { - /* Set the VgaAdapter as primary */ - gpPrimaryGraphicsDevice = gpVgaGraphicsDevice; - // FIXME: DEVMODE - } - else - { - ERR("Could not find VGA compatible driver. Trying normal.\n"); - } - }
/* Check if we had any success */ if (!gpPrimaryGraphicsDevice) @@ -326,6 +246,12 @@ UserEnumDisplayDevices( HKEY hkey; NTSTATUS Status;
+ if (!pustrDevice) + { + /* Check if some devices have been added since last time */ + EngpUpdateGraphicsDeviceList(); + } + /* Ask gdi for the GRAPHICS_DEVICE */ pGraphicsDevice = EngpFindGraphicsDevice(pustrDevice, iDevNum, 0); if (!pGraphicsDevice) diff --git a/win32ss/user/ntuser/ntuser.h b/win32ss/user/ntuser/ntuser.h index 379825056d1..78b6bacd965 100644 --- a/win32ss/user/ntuser/ntuser.h +++ b/win32ss/user/ntuser/ntuser.h @@ -48,4 +48,10 @@ RegWriteUserSetting( _In_reads_bytes_(cjDataSize) const VOID *pvData, _In_ ULONG cjDataSize);
+PGRAPHICS_DEVICE +NTAPI +InitDisplayDriver( + IN PWSTR pwszDeviceName, + IN PWSTR pwszRegKey); + /* EOF */