Author: tfaber Date: Mon Apr 17 19:44:32 2017 New Revision: 74359
URL: http://svn.reactos.org/svn/reactos?rev=74359&view=rev Log: [WIN32K:ENG] - Split populating the display mode list out from EngpRegisterGraphicsDevice, into its own function, EngpPopulateDeviceModeList. Based on a patch by Ismael Ferreras Morezuelas. CORE-6742
Modified: trunk/reactos/win32ss/gdi/eng/device.c trunk/reactos/win32ss/gdi/eng/device.h
Modified: trunk/reactos/win32ss/gdi/eng/device.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/device.c?re... ============================================================================== --- trunk/reactos/win32ss/gdi/eng/device.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/eng/device.c [iso-8859-1] Mon Apr 17 19:44:32 2017 @@ -30,99 +30,22 @@ return STATUS_SUCCESS; }
- -PGRAPHICS_DEVICE -NTAPI -EngpRegisterGraphicsDevice( - _In_ PUNICODE_STRING pustrDeviceName, - _In_ PUNICODE_STRING pustrDiplayDrivers, - _In_ PUNICODE_STRING pustrDescription, +BOOLEAN +EngpPopulateDeviceModeList( + _Inout_ PGRAPHICS_DEVICE pGraphicsDevice, _In_ PDEVMODEW pdmDefault) { - PGRAPHICS_DEVICE pGraphicsDevice; - PDEVICE_OBJECT pDeviceObject; - PFILE_OBJECT pFileObject; - NTSTATUS Status; PWSTR pwsz; - ULONG i, cj, cModes = 0; - SIZE_T cjWritten; - BOOL bEnable = TRUE; + PLDEVOBJ pldev; PDEVMODEINFO pdminfo; PDEVMODEW pdm, pdmEnd; - PLDEVOBJ pldev; + ULONG i, cModes = 0; BOOLEAN bModeMatch = FALSE;
- TRACE("EngpRegisterGraphicsDevice(%wZ)\n", pustrDeviceName); - - /* Allocate a GRAPHICS_DEVICE structure */ - pGraphicsDevice = ExAllocatePoolWithTag(PagedPool, - sizeof(GRAPHICS_DEVICE), - GDITAG_GDEVICE); - if (!pGraphicsDevice) - { - ERR("ExAllocatePoolWithTag failed\n"); - return NULL; - } - - /* Try to open the driver */ - Status = IoGetDeviceObjectPointer(pustrDeviceName, - FILE_READ_DATA | FILE_WRITE_DATA, - &pFileObject, - &pDeviceObject); - if (!NT_SUCCESS(Status)) - { - ERR("Could not open driver %wZ, 0x%lx\n", pustrDeviceName, Status); - ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE); - return NULL; - } - - /* Enable the device */ - EngFileWrite(pFileObject, &bEnable, sizeof(BOOL), &cjWritten); - - /* Copy the device and file object pointers */ - pGraphicsDevice->DeviceObject = pDeviceObject; - pGraphicsDevice->FileObject = pFileObject; - - /* Copy device name */ - RtlStringCbCopyNW(pGraphicsDevice->szNtDeviceName, - sizeof(pGraphicsDevice->szNtDeviceName), - pustrDeviceName->Buffer, - pustrDeviceName->Length); - - /* Create a win device name (FIXME: virtual devices!) */ - swprintf(pGraphicsDevice->szWinDeviceName, L"\\.\DISPLAY%d", (int)giDevNum); - - /* Allocate a buffer for the strings */ - cj = pustrDiplayDrivers->Length + pustrDescription->Length + sizeof(WCHAR); - pwsz = ExAllocatePoolWithTag(PagedPool, cj, GDITAG_DRVSUP); - if (!pwsz) - { - ERR("Could not allocate string buffer\n"); - ASSERT(FALSE); // FIXME - ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE); - return NULL; - } - - /* Copy display driver names */ - pGraphicsDevice->pDiplayDrivers = pwsz; - RtlCopyMemory(pGraphicsDevice->pDiplayDrivers, - pustrDiplayDrivers->Buffer, - pustrDiplayDrivers->Length); - - /* Copy description */ - pGraphicsDevice->pwszDescription = pwsz + pustrDiplayDrivers->Length / sizeof(WCHAR); - RtlCopyMemory(pGraphicsDevice->pwszDescription, - pustrDescription->Buffer, - pustrDescription->Length); - pGraphicsDevice->pwszDescription[pustrDescription->Length/sizeof(WCHAR)] = 0; - - /* Initialize the pdevmodeInfo list and default index */ - pGraphicsDevice->pdevmodeInfo = NULL; - pGraphicsDevice->iDefaultMode = 0; - pGraphicsDevice->iCurrentMode = 0; - - // FIXME: initialize state flags - pGraphicsDevice->StateFlags = 0; + ASSERT(pGraphicsDevice->pdevmodeInfo == NULL); + ASSERT(pGraphicsDevice->pDevModeList == NULL); + + pwsz = pGraphicsDevice->pDiplayDrivers;
/* Loop through the driver names * This is a REG_MULTI_SZ string */ @@ -138,7 +61,7 @@ }
/* Get the mode list from the driver */ - pdminfo = LDEVOBJ_pdmiGetModes(pldev, pDeviceObject); + pdminfo = LDEVOBJ_pdmiGetModes(pldev, pGraphicsDevice->DeviceObject); if (!pdminfo) { ERR("Could not get mode list for '%ls'\n", pwsz); @@ -170,8 +93,7 @@ if (!pGraphicsDevice->pdevmodeInfo || cModes == 0) { ERR("No devmodes\n"); - ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE); - return NULL; + return FALSE; }
/* Allocate an index buffer */ @@ -182,8 +104,7 @@ if (!pGraphicsDevice->pDevModeList) { ERR("No devmode list\n"); - ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE); - return NULL; + return FALSE; }
TRACE("Looking for mode %lux%lux%lu(%lu Hz)\n", @@ -232,7 +153,106 @@ pGraphicsDevice->pDevModeList[i].pdm = pdm; i++; } - } + } + return TRUE; +} + +PGRAPHICS_DEVICE +NTAPI +EngpRegisterGraphicsDevice( + _In_ PUNICODE_STRING pustrDeviceName, + _In_ PUNICODE_STRING pustrDiplayDrivers, + _In_ PUNICODE_STRING pustrDescription, + _In_ PDEVMODEW pdmDefault) +{ + PGRAPHICS_DEVICE pGraphicsDevice; + PDEVICE_OBJECT pDeviceObject; + PFILE_OBJECT pFileObject; + NTSTATUS Status; + PWSTR pwsz; + ULONG cj; + SIZE_T cjWritten; + BOOL bEnable = TRUE; + + TRACE("EngpRegisterGraphicsDevice(%wZ)\n", pustrDeviceName); + + /* Allocate a GRAPHICS_DEVICE structure */ + pGraphicsDevice = ExAllocatePoolWithTag(PagedPool, + sizeof(GRAPHICS_DEVICE), + GDITAG_GDEVICE); + if (!pGraphicsDevice) + { + ERR("ExAllocatePoolWithTag failed\n"); + return NULL; + } + + /* Try to open the driver */ + Status = IoGetDeviceObjectPointer(pustrDeviceName, + FILE_READ_DATA | FILE_WRITE_DATA, + &pFileObject, + &pDeviceObject); + if (!NT_SUCCESS(Status)) + { + ERR("Could not open driver %wZ, 0x%lx\n", pustrDeviceName, Status); + ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE); + return NULL; + } + + /* Enable the device */ + EngFileWrite(pFileObject, &bEnable, sizeof(BOOL), &cjWritten); + + /* Copy the device and file object pointers */ + pGraphicsDevice->DeviceObject = pDeviceObject; + pGraphicsDevice->FileObject = pFileObject; + + /* Copy device name */ + RtlStringCbCopyNW(pGraphicsDevice->szNtDeviceName, + sizeof(pGraphicsDevice->szNtDeviceName), + pustrDeviceName->Buffer, + pustrDeviceName->Length); + + /* Create a win device name (FIXME: virtual devices!) */ + swprintf(pGraphicsDevice->szWinDeviceName, L"\\.\DISPLAY%d", (int)giDevNum); + + /* Allocate a buffer for the strings */ + cj = pustrDiplayDrivers->Length + pustrDescription->Length + sizeof(WCHAR); + pwsz = ExAllocatePoolWithTag(PagedPool, cj, GDITAG_DRVSUP); + if (!pwsz) + { + ERR("Could not allocate string buffer\n"); + ASSERT(FALSE); // FIXME + ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE); + return NULL; + } + + /* Copy display driver names */ + pGraphicsDevice->pDiplayDrivers = pwsz; + RtlCopyMemory(pGraphicsDevice->pDiplayDrivers, + pustrDiplayDrivers->Buffer, + pustrDiplayDrivers->Length); + + /* Copy description */ + pGraphicsDevice->pwszDescription = pwsz + pustrDiplayDrivers->Length / sizeof(WCHAR); + RtlCopyMemory(pGraphicsDevice->pwszDescription, + pustrDescription->Buffer, + pustrDescription->Length); + pGraphicsDevice->pwszDescription[pustrDescription->Length/sizeof(WCHAR)] = 0; + + /* Initialize the pdevmodeInfo list and default index */ + pGraphicsDevice->pdevmodeInfo = NULL; + pGraphicsDevice->iDefaultMode = 0; + pGraphicsDevice->iCurrentMode = 0; + + // FIXME: initialize state flags + pGraphicsDevice->StateFlags = 0; + + /* Create the mode list */ + pGraphicsDevice->pDevModeList = NULL; + if (!EngpPopulateDeviceModeList(pGraphicsDevice, pdmDefault)) + { + ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE); + return NULL; + }
/* Lock loader */ EngAcquireSemaphore(ghsemGraphicsDeviceList); @@ -250,7 +270,7 @@
/* Unlock loader */ EngReleaseSemaphore(ghsemGraphicsDeviceList); - TRACE("Prepared %lu modes for %ls\n", cModes, pGraphicsDevice->pwszDescription); + TRACE("Prepared %lu modes for %ls\n", pGraphicsDevice->cDevModes, pGraphicsDevice->pwszDescription);
return pGraphicsDevice; }
Modified: trunk/reactos/win32ss/gdi/eng/device.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/device.h?re... ============================================================================== --- trunk/reactos/win32ss/gdi/eng/device.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/eng/device.h [iso-8859-1] Mon Apr 17 19:44:32 2017 @@ -29,6 +29,11 @@ _In_ PUNICODE_STRING pustrDescription, _In_ PDEVMODEW pdmDefault);
+BOOLEAN +EngpPopulateDeviceModeList( + _Inout_ PGRAPHICS_DEVICE pGraphicsDevice, + _In_ PDEVMODEW pdmDefault); + INIT_FUNCTION NTSTATUS NTAPI