https://git.reactos.org/?p=reactos.git;a=commitdiff;h=21ddeb76d91c851d95b6ab...
commit 21ddeb76d91c851d95b6ab563517f5ee071b9848 Author: Hervé Poussineau hpoussin@reactos.org AuthorDate: Sun Jan 9 10:33:10 2022 +0100 Commit: hpoussin 32227662+hpoussin@users.noreply.github.com CommitDate: Fri Apr 15 23:09:16 2022 +0200
[WIN32SS] Extract devmode list query to new function LDEVOBJ_bBuildDevmodeList
LDEVOBJ_bBuildDevmodeList() only queries the available display modes, without choosing the one to use on the graphic device, and without immediately creating a PDEV.
Replace first part of EngpPopulateDeviceModeList() function by a call to this new function LDEVOBJ_bBuildDevmodeList(). Keep second part of EngpPopulateDeviceModeList() function, which chooses the default display mode. --- win32ss/gdi/eng/device.c | 92 +++------------------------------------ win32ss/gdi/eng/ldevobj.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++ win32ss/gdi/eng/ldevobj.h | 4 ++ 3 files changed, 118 insertions(+), 85 deletions(-)
diff --git a/win32ss/gdi/eng/device.c b/win32ss/gdi/eng/device.c index 27edfe2a56e..8ad49ed5fd1 100644 --- a/win32ss/gdi/eng/device.c +++ b/win32ss/gdi/eng/device.c @@ -129,81 +129,17 @@ EngpPopulateDeviceModeList( _Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault) { - PWSTR pwsz; PDEVMODEINFO pdminfo; - PDEVMODEW pdm, pdmEnd; - ULONG i, cModes = 0; + PDEVMODEW pdm; + ULONG i; BOOLEAN bModeMatch = FALSE; - ULONG cbSize, cbFull;
ASSERT(pGraphicsDevice->pdevmodeInfo == NULL); ASSERT(pGraphicsDevice->pDevModeList == NULL);
- pwsz = pGraphicsDevice->pDiplayDrivers; - - /* Loop through the driver names - * This is a REG_MULTI_SZ string */ - for (; *pwsz; pwsz += wcslen(pwsz) + 1) - { - /* Get the mode list from the driver */ - TRACE("Trying driver: %ls\n", pwsz); - cbSize = LDEVOBJ_ulGetDriverModes(pwsz, pGraphicsDevice->DeviceObject, &pdm); - if (!cbSize) - { - WARN("Driver %ls returned no valid mode\n", pwsz); - continue; - } - - /* Add space for the header */ - cbFull = cbSize + FIELD_OFFSET(DEVMODEINFO, adevmode); - - /* Allocate a buffer for the DEVMODE array */ - pdminfo = ExAllocatePoolWithTag(PagedPool, cbFull, GDITAG_DEVMODE); - if (!pdminfo) - { - ERR("Could not allocate devmodeinfo\n"); - continue; - } - - pdminfo->pldev = LDEVOBJ_pLoadDriver(pwsz, LDEV_DEVICE_DISPLAY); - pdminfo->cbdevmode = cbSize; - RtlCopyMemory(pdminfo->adevmode, pdm, cbSize); - - /* Attach the mode info to the device */ - pdminfo->pdmiNext = pGraphicsDevice->pdevmodeInfo; - pGraphicsDevice->pdevmodeInfo = pdminfo; - - /* Loop all DEVMODEs */ - pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode); - for (pdm = pdminfo->adevmode; - (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0); - pdm = (DEVMODEW*)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra)) - { - /* Count this DEVMODE */ - cModes++; - - /* Some drivers like the VBox driver don't fill the dmDeviceName - with the name of the display driver. So fix that here. */ - RtlStringCbCopyW(pdm->dmDeviceName, sizeof(pdm->dmDeviceName), pwsz); - } - - // FIXME: release the driver again until it's used? - } - - if (!pGraphicsDevice->pdevmodeInfo || cModes == 0) + if (!LDEVOBJ_bBuildDevmodeList(pGraphicsDevice)) { - ERR("No devmodes\n"); - return FALSE; - } - - /* Allocate an index buffer */ - pGraphicsDevice->cDevModes = cModes; - pGraphicsDevice->pDevModeList = ExAllocatePoolWithTag(PagedPool, - cModes * sizeof(DEVMODEENTRY), - GDITAG_GDEVICE); - if (!pGraphicsDevice->pDevModeList) - { - ERR("No devmode list\n"); + ERR("LDEVOBJ_bBuildDevmodeList() failed\n"); return FALSE; }
@@ -218,20 +154,11 @@ EngpPopulateDeviceModeList( pdminfo; pdminfo = pdminfo->pdmiNext) { - /* Calculate End of the DEVMODEs */ - pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode); - /* Loop through the DEVMODEs */ - for (pdm = pdminfo->adevmode; - (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0); - pdm = (PDEVMODEW)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra)) + for (i = 0; i < pGraphicsDevice->cDevModes; i++) { - TRACE(" %S has mode %lux%lux%lu(%lu Hz)\n", - pdm->dmDeviceName, - pdm->dmPelsWidth, - pdm->dmPelsHeight, - pdm->dmBitsPerPel, - pdm->dmDisplayFrequency); + pdm = pGraphicsDevice->pDevModeList[i].pdm; + /* Compare with the default entry */ if (!bModeMatch && pdm->dmBitsPerPel == pdmDefault->dmBitsPerPel && @@ -247,11 +174,6 @@ EngpPopulateDeviceModeList( bModeMatch = TRUE; } } - - /* Initialize the entry */ - pGraphicsDevice->pDevModeList[i].dwFlags = 0; - pGraphicsDevice->pDevModeList[i].pdm = pdm; - i++; } } return TRUE; diff --git a/win32ss/gdi/eng/ldevobj.c b/win32ss/gdi/eng/ldevobj.c index b1cdc7b1247..e2079da8178 100644 --- a/win32ss/gdi/eng/ldevobj.c +++ b/win32ss/gdi/eng/ldevobj.c @@ -450,6 +450,113 @@ leave: return pldev; }
+BOOL +LDEVOBJ_bBuildDevmodeList( + _Inout_ PGRAPHICS_DEVICE pGraphicsDevice) +{ + PWSTR pwsz; + PDEVMODEINFO pdminfo; + PDEVMODEW pdm, pdmEnd; + ULONG i, cModes = 0; + ULONG cbSize, cbFull; + + if (pGraphicsDevice->pdevmodeInfo) + return TRUE; + ASSERT(pGraphicsDevice->pDevModeList == NULL); + + pwsz = pGraphicsDevice->pDiplayDrivers; + + /* Loop through the driver names + * This is a REG_MULTI_SZ string */ + for (; *pwsz; pwsz += wcslen(pwsz) + 1) + { + /* Get the mode list from the driver */ + TRACE("Trying driver: %ls\n", pwsz); + cbSize = LDEVOBJ_ulGetDriverModes(pwsz, pGraphicsDevice->DeviceObject, &pdm); + if (!cbSize) + { + WARN("Driver %ls returned no valid mode\n", pwsz); + continue; + } + + /* Add space for the header */ + cbFull = cbSize + FIELD_OFFSET(DEVMODEINFO, adevmode); + + /* Allocate a buffer for the DEVMODE array */ + pdminfo = ExAllocatePoolWithTag(PagedPool, cbFull, GDITAG_DEVMODE); + if (!pdminfo) + { + ERR("Could not allocate devmodeinfo\n"); + continue; + } + + pdminfo->cbdevmode = cbSize; + RtlCopyMemory(pdminfo->adevmode, pdm, cbSize); + + /* Attach the mode info to the device */ + pdminfo->pdmiNext = pGraphicsDevice->pdevmodeInfo; + pGraphicsDevice->pdevmodeInfo = pdminfo; + + /* Loop all DEVMODEs */ + pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode); + for (pdm = pdminfo->adevmode; + (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0); + pdm = (DEVMODEW*)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra)) + { + /* Count this DEVMODE */ + cModes++; + + /* Some drivers like the VBox driver don't fill the dmDeviceName + with the name of the display driver. So fix that here. */ + RtlStringCbCopyW(pdm->dmDeviceName, sizeof(pdm->dmDeviceName), pwsz); + } + } + + if (!pGraphicsDevice->pdevmodeInfo || cModes == 0) + { + ERR("No devmodes\n"); + return FALSE; + } + + /* Allocate an index buffer */ + pGraphicsDevice->cDevModes = cModes; + pGraphicsDevice->pDevModeList = ExAllocatePoolWithTag(PagedPool, + cModes * sizeof(DEVMODEENTRY), + GDITAG_GDEVICE); + if (!pGraphicsDevice->pDevModeList) + { + ERR("No devmode list\n"); + return FALSE; + } + + /* Loop through all DEVMODEINFOs */ + for (pdminfo = pGraphicsDevice->pdevmodeInfo, i = 0; + pdminfo; + pdminfo = pdminfo->pdmiNext) + { + /* Calculate End of the DEVMODEs */ + pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode); + + /* Loop through the DEVMODEs */ + for (pdm = pdminfo->adevmode; + (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0); + pdm = (PDEVMODEW)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra)) + { + TRACE(" %S has mode %lux%lux%lu(%lu Hz)\n", + pdm->dmDeviceName, + pdm->dmPelsWidth, + pdm->dmPelsHeight, + pdm->dmBitsPerPel, + pdm->dmDisplayFrequency); + + /* Initialize the entry */ + pGraphicsDevice->pDevModeList[i].dwFlags = 0; + pGraphicsDevice->pDevModeList[i].pdm = pdm; + i++; + } + } + return TRUE; +}
/** Exported functions ********************************************************/
diff --git a/win32ss/gdi/eng/ldevobj.h b/win32ss/gdi/eng/ldevobj.h index 351328fe61e..cac2ec8f5e0 100644 --- a/win32ss/gdi/eng/ldevobj.h +++ b/win32ss/gdi/eng/ldevobj.h @@ -52,6 +52,10 @@ LDEVOBJ_pLoadDriver( _In_z_ LPWSTR pwszDriverName, _In_ ULONG ldevtype);
+BOOL +LDEVOBJ_bBuildDevmodeList( + _Inout_ PGRAPHICS_DEVICE pGraphicsDevice); + PLDEVOBJ NTAPI EngGetLDEV(