[WIN32SS] Add missing code parts for monitor handling 4526/head
authorStanislav Motylkov <x86corez@gmail.com>
Tue, 24 May 2022 21:18:10 +0000 (00:18 +0300)
committerStanislav Motylkov <x86corez@gmail.com>
Mon, 30 May 2022 12:28:44 +0000 (15:28 +0300)
- [VIDEOPRT] Add stub for IOCTL_VIDEO_ENUM_MONITOR_PDO.

- [WIN32SS:ENG] Add missing checks and comments.

- [WIN32SS:NTUSER] Add missing monitor handling and comments.

Addendum to 31827c43. CORE-18197 CORE-11715

win32ss/drivers/videoprt/dispatch.c
win32ss/gdi/eng/device.c
win32ss/user/ntuser/display.c

index 1878e79..79a2048 100644 (file)
@@ -790,6 +790,11 @@ IntVideoPortDispatchDeviceControl(
             Status = STATUS_NOT_IMPLEMENTED;
             break;
 
+        case IOCTL_VIDEO_ENUM_MONITOR_PDO:
+            WARN_(VIDEOPRT, "- IOCTL_VIDEO_ENUM_MONITOR_PDO is UNIMPLEMENTED!\n");
+            Status = STATUS_NOT_IMPLEMENTED;
+            break;
+
         case IOCTL_VIDEO_INIT_WIN32K_CALLBACKS:
             INFO_(VIDEOPRT, "- IOCTL_VIDEO_INIT_WIN32K_CALLBACKS\n");
             Status = VideoPortInitWin32kCallbacks(DeviceObject,
index af6bd3e..3bd3827 100644 (file)
@@ -351,6 +351,19 @@ EngpRegisterGraphicsDevice(
     // if (Win32kCallbacks.DualviewFlags & ???)
     pGraphicsDevice->PhysDeviceHandle = Win32kCallbacks.pPhysDeviceObject;
 
+    /* FIXME: Enumerate children monitor devices for this video adapter
+     *
+     * - Force the adapter to re-enumerate its monitors:
+     *   IoSynchronousInvalidateDeviceRelations(pdo, BusRelations)
+     *
+     * - Retrieve all monitor PDOs from VideoPrt:
+     *   EngDeviceIoControl(0x%p, IOCTL_VIDEO_ENUM_MONITOR_PDO)
+     *
+     * - Initialize these fields and structures accordingly:
+     *   pGraphicsDevice->dwMonCnt
+     *   pGraphicsDevice->pvMonDev[0..dwMonCnt-1]
+     */
+
     /* Copy the device name */
     RtlStringCbCopyNW(pGraphicsDevice->szNtDeviceName,
                       sizeof(pGraphicsDevice->szNtDeviceName),
@@ -445,7 +458,7 @@ EngpFindGraphicsDevice(
 
     if (pustrDevice && pustrDevice->Buffer)
     {
-        /* Loop through the list of devices */
+        /* Find specified video adapter by name */
         for (pGraphicsDevice = gpGraphicsDeviceFirst;
              pGraphicsDevice;
              pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice)
@@ -457,10 +470,21 @@ EngpFindGraphicsDevice(
                 break;
             }
         }
+
+        if (pGraphicsDevice)
+        {
+            /* Validate selected monitor number */
+#if 0
+            if (iDevNum >= pGraphicsDevice->dwMonCnt)
+                pGraphicsDevice = NULL;
+#else
+            /* FIXME: dwMonCnt not initialized, see EngpRegisterGraphicsDevice */
+#endif
+        }
     }
     else
     {
-        /* Loop through the list of devices */
+        /* Select video adapter by device number */
         for (pGraphicsDevice = gpGraphicsDeviceFirst, i = 0;
              pGraphicsDevice && i < iDevNum;
              pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice, i++);
index 4d14c65..5feb807 100644 (file)
@@ -237,6 +237,7 @@ UserEnumDisplayDevices(
     DWORD dwFlags)
 {
     PGRAPHICS_DEVICE pGraphicsDevice;
+    PDEVICE_OBJECT pdo;
     PWCHAR pHardwareId;
     ULONG cbSize, dwLength;
     HKEY hkey;
@@ -284,9 +285,19 @@ UserEnumDisplayDevices(
     pdispdev->DeviceID[0] = UNICODE_NULL;
 
     /* Fill in DeviceID */
-    if (pGraphicsDevice->PhysDeviceHandle != NULL)
+    if (!pustrDevice)
+        pdo = pGraphicsDevice->PhysDeviceHandle;
+    else
+#if 0
+        pdo = pGraphicsDevice->pvMonDev[iDevNum].pdo;
+#else
+        /* FIXME: pvMonDev not initialized, see EngpRegisterGraphicsDevice */
+        pdo = NULL;
+#endif
+
+    if (pdo != NULL)
     {
-        Status = IoGetDeviceProperty(pGraphicsDevice->PhysDeviceHandle,
+        Status = IoGetDeviceProperty(pdo,
                                      DevicePropertyHardwareID,
                                      0,
                                      NULL,
@@ -303,7 +314,7 @@ UserEnumDisplayDevices(
                 return STATUS_INSUFFICIENT_RESOURCES;
             }
 
-            Status = IoGetDeviceProperty(pGraphicsDevice->PhysDeviceHandle,
+            Status = IoGetDeviceProperty(pdo,
                                          DevicePropertyHardwareID,
                                          dwLength,
                                          pHardwareId,
@@ -319,10 +330,19 @@ UserEnumDisplayDevices(
                  * which usually is the longest one and unique enough */
                 RtlStringCbCopyW(pdispdev->DeviceID, sizeof(pdispdev->DeviceID), pHardwareId);
 
-                /* For monitors it should be the first Hardware ID
-                 * concatenated with the unique driver registry key */
+                if (pustrDevice)
+                {
+                    /* For monitors it should be the first Hardware ID,
+                     * which we already have obtained above,
+                     * concatenated with the unique driver registry key */
+
+                    RtlStringCbCatW(pdispdev->DeviceID, sizeof(pdispdev->DeviceID), L"\\");
+
+                    /* FIXME: DevicePropertyDriverKeyName string should be appended */
+                    pHardwareId[0] = UNICODE_NULL;
+                    RtlStringCbCatW(pdispdev->DeviceID, sizeof(pdispdev->DeviceID), pHardwareId);
+                }
 
-                /* FIXME: Handle monitors! */
                 TRACE("Hardware ID: %ls\n", pdispdev->DeviceID);
             }