[CMAKE]
[reactos.git] / subsystems / win32 / win32k / ntuser / display.c
index c679b9a..f5770a7 100644 (file)
@@ -147,10 +147,9 @@ InitDisplayDriver(
     return pGraphicsDevice;
 }
 
-BOOL
-InitVideo(
-    PUNICODE_STRING pustrRegPath,
-    FLONG flags)
+NTSTATUS
+NTAPI
+InitVideo()
 {
     ULONG iDevNum, iVGACompatible = -1, ulMaxObjectNumber = 0;
     WCHAR awcDeviceName[20];
@@ -160,8 +159,9 @@ InitVideo(
     ULONG cbValue;
     HKEY hkey;
 
-    DPRINT1("----------------------------- InitVideo() -------------------------------\n");
+    DPRINT("----------------------------- InitVideo() -------------------------------\n");
 
+    /* Open the key for the boot command line */
     Status = RegOpenKey(L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control", &hkey);
     if (NT_SUCCESS(Status))
     {
@@ -185,7 +185,7 @@ InitVideo(
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Could not open device registry key!\n");
-        ASSERT(FALSE);
+        return Status;
     }
 
     /* Read the name of the VGA adapter */
@@ -206,16 +206,23 @@ InitVideo(
     DPRINT("Found %ld devices\n", ulMaxObjectNumber);
 
     /* Loop through all adapters */
-    cbValue = 256;
     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))
+        {
+            DPRINT1("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 the VGA adapter */
         if (iDevNum == iVGACompatible)
@@ -230,8 +237,16 @@ InitVideo(
             gpPrimaryGraphicsDevice = pGraphicsDevice;
     }
 
+    /* Close the device map registry key */
     ZwClose(hkey);
 
+    /* Check if we had any success */
+    if (!gpPrimaryGraphicsDevice)
+    {
+        DPRINT1("No usable display driver was found.\n");
+        return STATUS_UNSUCCESSFUL;
+    }
+
     if (gbBaseVideo)
     {
         if (gpVgaGraphicsDevice)
@@ -317,8 +332,8 @@ NtUserEnumDisplayDevices(
     DISPLAY_DEVICEW dispdev;
     NTSTATUS Status;
 
-    DPRINT1("Enter NtUserEnumDisplayDevices(%p, %ls, %ld)\n",
-            pustrDevice, pustrDevice ? pustrDevice->Buffer : 0, iDevNum);
+    DPRINT("Enter NtUserEnumDisplayDevices(%wZ, %ld)\n",
+           pustrDevice, iDevNum);
 
     // FIXME: HACK, desk.cpl passes broken crap
     if (pustrDevice && iDevNum != 0)
@@ -430,11 +445,12 @@ UserEnumDisplaySettings(
     PDEVMODEENTRY pdmentry;
     ULONG i, iFoundMode;
 
-    DPRINT1("Enter UserEnumDisplaySettings('%ls', %ld)\n",
+    DPRINT("Enter UserEnumDisplaySettings('%ls', %ld)\n",
             pustrDevice ? pustrDevice->Buffer : NULL, iModeNum);
 
     /* Ask gdi for the GRAPHICS_DEVICE */
     pGraphicsDevice = EngpFindGraphicsDevice(pustrDevice, 0, 0);
+
     if (!pGraphicsDevice)
     {
         /* No device found */
@@ -442,19 +458,19 @@ UserEnumDisplaySettings(
         return STATUS_UNSUCCESSFUL;
     }
 
-    if (iModeNum == 0)
-    {
-        DPRINT1("Should initialize modes somehow\n");
-        // Update DISPLAY_DEVICEs?
-    }
+    if (iModeNum >= pGraphicsDevice->cDevModes)
+        return STATUS_NO_MORE_ENTRIES;
 
     iFoundMode = 0;
     for (i = 0; i < pGraphicsDevice->cDevModes; i++)
     {
         pdmentry = &pGraphicsDevice->pDevModeList[i];
 
-//        if ((!(dwFlags & EDS_RAWMODE) && (pdmentry->dwFlags & 1)) || // FIXME!
-//            (dwFlags & EDS_RAWMODE))
+        /* FIXME: consider EDS_RAWMODE */
+#if 0
+        if ((!(dwFlags & EDS_RAWMODE) && (pdmentry->dwFlags & 1)) ||!
+            (dwFlags & EDS_RAWMODE))
+#endif
         {
             /* Is this the one we want? */
             if (iFoundMode == iModeNum)
@@ -536,7 +552,7 @@ NtUserEnumDisplaySettings(
     DEVMODEW dmReg, *pdm;
 
     DPRINT1("Enter NtUserEnumDisplaySettings(%ls, %ld)\n",
-            pustrDevice ? pustrDevice->Buffer:0, iModeNum);
+            pustrDevice ? pustrDevice->Buffer : 0, iModeNum);
 
     if (pustrDevice)
     {
@@ -668,8 +684,12 @@ UserChangeDisplaySettings(
     }
 
     /* Fixup values */
-    if((dm.dmFields & DM_BITSPERPEL) && (dm.dmBitsPerPel == 0))
+    if(dm.dmBitsPerPel == 0 || !(dm.dmFields & DM_BITSPERPEL))
+    {
         dm.dmBitsPerPel = ppdev->pdmwDev->dmBitsPerPel;
+        dm.dmFields |= DM_BITSPERPEL;
+    }
+
     if((dm.dmFields & DM_DISPLAYFREQUENCY) && (dm.dmDisplayFrequency == 0))
         dm.dmDisplayFrequency = ppdev->pdmwDev->dmDisplayFrequency;