https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9acd895f1849350d7bc652ee55be2515ef80f98a

commit 9acd895f1849350d7bc652ee55be2515ef80f98a
Author:     Hervé Poussineau <[email protected]>
AuthorDate: Sun May 22 14:21:34 2022 +0200
Commit:     Hervé Poussineau <[email protected]>
CommitDate: Sun May 22 17:32:40 2022 +0200

    [WIN32SS] Copy loading of registry settings from mdevobj.c to new function
    
    This function will be used in next commit, and duplicated implementation
    in mdevobj.c will be dropped.
---
 win32ss/gdi/eng/device.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++
 win32ss/gdi/eng/device.h | 13 +++++++
 2 files changed, 108 insertions(+)

diff --git a/win32ss/gdi/eng/device.c b/win32ss/gdi/eng/device.c
index 037b0261a47..2b96ca409c9 100644
--- a/win32ss/gdi/eng/device.c
+++ b/win32ss/gdi/eng/device.c
@@ -124,6 +124,101 @@ EngpUpdateGraphicsDeviceList(VOID)
     return STATUS_SUCCESS;
 }
 
+/* Open display settings registry key
+ * Returns NULL in case of error. */
+static HKEY
+EngpGetRegistryHandleFromDeviceMap(
+    _In_ PGRAPHICS_DEVICE pGraphicsDevice)
+{
+    static const PWCHAR KEY_VIDEO = 
L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO";
+    HKEY hKey;
+    WCHAR szDeviceKey[256];
+    ULONG cbSize;
+    NTSTATUS Status;
+
+    /* Open the device map registry key */
+    Status = RegOpenKey(KEY_VIDEO, &hKey);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("Could not open HARDWARE\\DEVICEMAP\\VIDEO registry key: status 
0x%08x\n", Status);
+        return NULL;
+    }
+
+    /* Query the registry path */
+    cbSize = sizeof(szDeviceKey);
+    RegQueryValue(hKey,
+                  pGraphicsDevice->szNtDeviceName,
+                  REG_SZ,
+                  szDeviceKey,
+                  &cbSize);
+    ZwClose(hKey);
+
+    /* Open the registry key */
+    Status = RegOpenKey(szDeviceKey, &hKey);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("Could not open registry key '%S': status 0x%08x\n", szDeviceKey, 
Status);
+        return NULL;
+    }
+
+    return hKey;
+}
+
+NTSTATUS
+EngpGetDisplayDriverParameters(
+    _In_ PGRAPHICS_DEVICE pGraphicsDevice,
+    _Out_ PDEVMODEW pdm,
+    _Out_opt_ PDWORD pdwAccelerationLevel)
+{
+    HKEY hKey;
+    DWORD dwDummy;
+    NTSTATUS Status;
+    RTL_QUERY_REGISTRY_TABLE DisplaySettingsTable[] =
+    {
+        {
+            NULL,
+            RTL_QUERY_REGISTRY_DIRECT,
+            L"Acceleration.Level",
+            pdwAccelerationLevel ? pdwAccelerationLevel : &dwDummy,
+            REG_NONE, NULL, 0
+        },
+#define READ(field, str) \
+        { \
+            NULL, \
+            RTL_QUERY_REGISTRY_DIRECT, \
+            L ##str, \
+            &pdm->field, \
+            REG_NONE, NULL, 0 \
+        },
+    READ(dmBitsPerPel, "DefaultSettings.BitsPerPel")
+    READ(dmPelsWidth, "DefaultSettings.XResolution")
+    READ(dmPelsHeight, "DefaultSettings.YResolution")
+    READ(dmDisplayFlags, "DefaultSettings.Flags")
+    READ(dmDisplayFrequency, "DefaultSettings.VRefresh")
+    READ(dmPanningWidth, "DefaultSettings.XPanning")
+    READ(dmPanningHeight, "DefaultSettings.YPanning")
+    READ(dmDisplayOrientation, "DefaultSettings.Orientation")
+    READ(dmDisplayFixedOutput, "DefaultSettings.FixedOutput")
+    READ(dmPosition.x, "Attach.RelativeX")
+    READ(dmPosition.y, "Attach.RelativeY")
+#undef READ
+        {0}
+    };
+
+    hKey = EngpGetRegistryHandleFromDeviceMap(pGraphicsDevice);
+    if (!hKey)
+        return STATUS_UNSUCCESSFUL;
+
+    Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
+                                    (PWSTR)hKey,
+                                    DisplaySettingsTable,
+                                    NULL,
+                                    NULL);
+
+    ZwClose(hKey);
+    return Status;
+}
+
 extern VOID
 UserRefreshDisplay(IN PPDEVOBJ ppdev);
 
diff --git a/win32ss/gdi/eng/device.h b/win32ss/gdi/eng/device.h
index cb211d4c055..5791e5a5591 100644
--- a/win32ss/gdi/eng/device.h
+++ b/win32ss/gdi/eng/device.h
@@ -35,6 +35,19 @@ EngpRegisterGraphicsDevice(
 NTSTATUS
 EngpUpdateGraphicsDeviceList(VOID);
 
+/* Read configuration of a graphics card from registry:
+ * - pGraphicsDevice: instance of the graphics card
+ * - pdm: on output, contains the values read in registry
+ * - pdwAccelerationLevel: acceleration level stored in registry
+ * Return value: a STATUS_* value
+ * Assume that pdm has already been zero-filled.
+ * Note that dmFields is not updated. */
+NTSTATUS
+EngpGetDisplayDriverParameters(
+    _In_ PGRAPHICS_DEVICE pGraphicsDevice,
+    _Out_ PDEVMODEW pdm,
+    _Out_opt_ PDWORD pdwAccelerationLevel);
+
 CODE_SEG("INIT")
 NTSTATUS
 NTAPI

Reply via email to