[PATCH 5/7] winex11.drv: Initialize adapter registry data.

Zhiyi Zhang zzhang at codeweavers.com
Wed Mar 20 03:10:09 CDT 2019


Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/user32/tests/monitor.c |  4 +-
 dlls/winex11.drv/display.c  | 96 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 96 insertions(+), 4 deletions(-)

diff --git a/dlls/user32/tests/monitor.c b/dlls/user32/tests/monitor.c
index 9a661569ac..c8a6fe0181 100644
--- a/dlls/user32/tests/monitor.c
+++ b/dlls/user32/tests/monitor.c
@@ -113,9 +113,9 @@ static void test_enumdisplaydevices_adapter(int index, const DISPLAY_DEVICEA *de
             memset(video_value, 0, sizeof(video_value));
             size = sizeof(video_value);
             ls = RegQueryValueExA(hkey, video_name, NULL, NULL, (unsigned char *)video_value, &size);
-            todo_wine ok(!ls, "#%d: failed to get registry value, error: %#x\n", index, ls);
+            ok(!ls, "#%d: failed to get registry value, error: %#x\n", index, ls);
             RegCloseKey(hkey);
-            ok(!strcmp(video_value, device->DeviceKey), "#%d: wrong DeviceKey: %s\n", index, device->DeviceKey);
+            todo_wine ok(!strcmp(video_value, device->DeviceKey), "#%d: wrong DeviceKey: %s\n", index, device->DeviceKey);
         }
     }
     else
diff --git a/dlls/winex11.drv/display.c b/dlls/winex11.drv/display.c
index 86be731384..a5e201e0a9 100644
--- a/dlls/winex11.drv/display.c
+++ b/dlls/winex11.drv/display.c
@@ -42,6 +42,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
 static const WCHAR driver_descW[] = {'D','r','i','v','e','r','D','e','s','c',0};
 static const WCHAR graphics_driverW[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
 static const WCHAR video_idW[] = {'V','i','d','e','o','I','D',0};
+static const WCHAR symbolic_link_valueW[]= {'S','y','m','b','o','l','i','c','L','i','n','k','V','a','l','u','e',0};
+static const WCHAR gpu_idW[] = {'G','P','U','I','D',0};
+static const WCHAR state_flagsW[] = {'S','t','a','t','e','F','l','a','g','s',0};
 static const WCHAR guid_fmtW[] = {
     '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-','%','0','2','x','%','0','2','x','-',
     '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
@@ -74,6 +77,19 @@ static const WCHAR video_keyW[] = {
     'H','A','R','D','W','A','R','E','\\',
     'D','E','V','I','C','E','M','A','P','\\',
     'V','I','D','E','O',0};
+static const WCHAR adapter_key_fmtW[] = {
+    'S','y','s','t','e','m','\\',
+    'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+    'C','o','n','t','r','o','l','\\',
+    'V','i','d','e','o','\\',
+    '%','s','\\',
+    '%','0','4','x',0};
+static const WCHAR device_video_fmtW[] = {
+    '\\','D','e','v','i','c','e','\\',
+    'V','i','d','e','o','%','d',0};
+static const WCHAR machine_prefixW[] = {
+    '\\','R','e','g','i','s','t','r','y','\\',
+    'M','a','c','h','i','n','e','\\',0};
 
 static struct x11drv_display_device_handler handler;
 
@@ -169,6 +185,62 @@ fail:
     return ret;
 }
 
+static BOOL X11DRV_InitAdapter(HKEY video_hkey, INT video_index, INT gpu_index, INT adapter_index,
+                               const struct x11drv_gpu *gpu, const WCHAR *guid_string,
+                               const WCHAR *gpu_driver, const struct x11drv_adapter *adapter)
+{
+    WCHAR adapter_keyW[MAX_PATH];
+    WCHAR key_nameW[MAX_PATH];
+    WCHAR bufferW[MAX_PATH];
+    HKEY hkey = NULL;
+    LSTATUS ls;
+    BOOL ret = FALSE;
+
+    sprintfW(key_nameW, device_video_fmtW, video_index);
+    strcpyW(bufferW, machine_prefixW);
+    sprintfW(adapter_keyW, adapter_key_fmtW, guid_string, adapter_index);
+    strcatW(bufferW, adapter_keyW);
+
+    /* Write value of \Device\Video? (adapter key) in HKLM\HARDWARE\DEVICEMAP\VIDEO\ */
+    if (RegSetValueExW(video_hkey, key_nameW, 0, REG_SZ, (const BYTE *)bufferW, (strlenW(bufferW) + 1) * sizeof(WCHAR)))
+        goto fail;
+
+    /* Create HKLM\System\CurrentControlSet\Control\Video\{GPU GUID}\{Adapter Index} link to GPU driver */
+    ls = RegCreateKeyExW(HKEY_LOCAL_MACHINE, adapter_keyW, 0, NULL, REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK,
+                         KEY_ALL_ACCESS, NULL, &hkey, NULL);
+    if (ls == ERROR_ALREADY_EXISTS)
+        RegOpenKeyExW(HKEY_LOCAL_MACHINE, adapter_keyW, REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, &hkey);
+    if (RegSetValueExW(hkey, symbolic_link_valueW, 0, REG_LINK, (const BYTE *)gpu_driver,
+                       strlenW(gpu_driver) * sizeof(WCHAR)))
+        goto fail;
+    RegCloseKey(hkey);
+    hkey = NULL;
+
+    /* FIXME:
+     * Following information are Wine specific, they don't really exist on Windows. They are used so that we can
+     * implement EnumDisplayDevices etc by querying registry only. These information are most likely reported by the
+     * device driver on Windows */
+    RegCreateKeyExW(HKEY_CURRENT_CONFIG, adapter_keyW, 0, NULL, REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
+
+    /* Write GPU instance path so that we can find the GPU instance via adapters quickly. Another way is trying to match
+     * them via the GUID in Device Paramters/VideoID, but it would required enumrating all GPU instances */
+    sprintfW(bufferW, gpu_instance_fmtW, gpu->vendor_id, gpu->device_id, gpu->subsys_id, gpu->revision_id, gpu_index);
+    if (RegSetValueExW(hkey, gpu_idW, 0, REG_SZ, (const BYTE *)bufferW, (strlenW(bufferW) + 1) * sizeof(WCHAR)))
+        goto fail;
+
+    /* Write StateFlags */
+    if (RegSetValueExW(hkey, state_flagsW, 0, REG_DWORD, (const BYTE *)&adapter->state_flags,
+                       sizeof(adapter->state_flags)))
+        goto fail;
+
+    ret = TRUE;
+fail:
+    RegCloseKey(hkey);
+    if (!ret)
+        ERR("Failed to initialize adapter\n");
+    return ret;
+}
+
 static void prepare_devices(void)
 {
     static const BOOL not_present = FALSE;
@@ -211,10 +283,12 @@ static void cleanup_devices(void)
 BOOL X11DRV_DisplayDevice_Init(void)
 {
     struct x11drv_gpu *gpus = NULL;
-    INT gpu_count;
-    INT gpu;
+    struct x11drv_adapter *adapters = NULL;
+    INT gpu_count, adapter_count;
+    INT gpu, adapter;
     HDEVINFO gpu_devinfo = NULL;
     HKEY video_hkey = NULL;
+    INT video_index = 0;
     DWORD disposition = 0;
     WCHAR guidW[40];
     WCHAR driverW[MAX_PATH];
@@ -250,6 +324,22 @@ BOOL X11DRV_DisplayDevice_Init(void)
     {
         if (!X11DRV_InitGpu(gpu_devinfo, &gpus[gpu], gpu, guidW, driverW))
             goto fail;
+
+        /* Initialize adapters */
+        if (!handler.pGetAdapters(gpus[gpu].id, &adapters, &adapter_count))
+            goto fail;
+
+        for (adapter = 0; adapter < adapter_count; adapter++)
+        {
+            if (!X11DRV_InitAdapter(video_hkey, video_index, gpu, adapter,
+                                    &gpus[gpu], guidW, driverW, &adapters[adapter]))
+                goto fail;
+
+            video_index++;
+        }
+
+        handler.pFreeAdapters(adapters);
+        adapters = NULL;
     }
 
     ret = TRUE;
@@ -259,6 +349,8 @@ fail:
     RegCloseKey(video_hkey);
     if (gpus)
         handler.pFreeGpus(gpus);
+    if (adapters)
+        handler.pFreeAdapters(adapters);
     if (!ret)
         ERR("Failed to initialize display devices\n");
     return ret;
-- 
2.19.2





More information about the wine-devel mailing list