[WIN32K:ENG]
authorThomas Faber <thomas.faber@reactos.org>
Mon, 17 Apr 2017 19:44:32 +0000 (19:44 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Mon, 17 Apr 2017 19:44:32 +0000 (19:44 +0000)
- Split populating the display mode list out from EngpRegisterGraphicsDevice, into its own function, EngpPopulateDeviceModeList. Based on a patch by Ismael Ferreras Morezuelas.
CORE-6742

svn path=/trunk/; revision=74359

reactos/win32ss/gdi/eng/device.c
reactos/win32ss/gdi/eng/device.h

index e1d6363..0123a27 100644 (file)
@@ -30,99 +30,22 @@ InitDeviceImpl(VOID)
     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);
+    ASSERT(pGraphicsDevice->pdevmodeInfo == NULL);
+    ASSERT(pGraphicsDevice->pDevModeList == NULL);
 
-    /* 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;
+    pwsz = pGraphicsDevice->pDiplayDrivers;
 
     /* Loop through the driver names
      * This is a REG_MULTI_SZ string */
@@ -138,7 +61,7 @@ EngpRegisterGraphicsDevice(
         }
 
         /* 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 @@ EngpRegisterGraphicsDevice(
     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 @@ EngpRegisterGraphicsDevice(
     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 @@ EngpRegisterGraphicsDevice(
             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 @@ EngpRegisterGraphicsDevice(
 
     /* 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;
 }
index e194456..35ac63a 100644 (file)
@@ -29,6 +29,11 @@ EngpRegisterGraphicsDevice(
     _In_ PUNICODE_STRING pustrDescription,
     _In_ PDEVMODEW pdmDefault);
 
+BOOLEAN
+EngpPopulateDeviceModeList(
+    _Inout_ PGRAPHICS_DEVICE pGraphicsDevice,
+    _In_ PDEVMODEW pdmDefault);
+
 INIT_FUNCTION
 NTSTATUS
 NTAPI