From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/sysparams.c | 60 ++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 5afad7f48b4..729effa841b 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -929,7 +929,7 @@ struct device_manager_ctx UINT source_count; UINT monitor_count; HANDLE mutex; - struct gpu gpu; + struct gpu *gpu; struct source source; HKEY source_key; /* for the virtual desktop settings */ @@ -1190,6 +1190,7 @@ static void add_gpu( const char *name, const struct pci_id *pci_id, const GUID * KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer; unsigned int i; HKEY hkey, subkey; + struct gpu *gpu; DWORD len;
TRACE( "%s %04X %04X %08X %02X\n", debugstr_a( name ), pci_id->vendor, pci_id->device, @@ -1205,36 +1206,37 @@ static void add_gpu( const char *name, const struct pci_id *pci_id, const GUID * prepare_devices(); }
- memset( &ctx->gpu, 0, sizeof(ctx->gpu) ); - ctx->gpu.index = ctx->gpu_count; + if (!(gpu = calloc( 1, sizeof(*gpu) ))) return; + gpu->refcount = 1; + gpu->index = ctx->gpu_count;
- if (vulkan_uuid) ctx->gpu.vulkan_uuid = *vulkan_uuid; - else if (!get_vulkan_gpu_info( pci_id, ctx->gpu.index, &ctx->gpu.vulkan_uuid, &vulkan_name )) WARN( "Failed to find GPU vulkan info\n" ); + if (vulkan_uuid) gpu->vulkan_uuid = *vulkan_uuid; + else if (!get_vulkan_gpu_info( pci_id, gpu->index, &gpu->vulkan_uuid, &vulkan_name )) WARN( "Failed to find GPU vulkan info\n" ); else if (!name) name = vulkan_name;
- if (name) RtlUTF8ToUnicodeN( ctx->gpu.name, sizeof(ctx->gpu.name) - sizeof(WCHAR), &len, name, strlen( name ) ); + if (name) RtlUTF8ToUnicodeN( gpu->name, sizeof(gpu->name) - sizeof(WCHAR), &len, name, strlen( name ) ); free( vulkan_name );
- snprintf( ctx->gpu.path, sizeof(ctx->gpu.path), "PCI\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X\%08X", - pci_id->vendor, pci_id->device, pci_id->subsystem, pci_id->revision, ctx->gpu.index ); - if (!(hkey = reg_create_ascii_key( enum_key, ctx->gpu.path, 0, NULL ))) return; + snprintf( gpu->path, sizeof(gpu->path), "PCI\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X\%08X", + pci_id->vendor, pci_id->device, pci_id->subsystem, pci_id->revision, gpu->index ); + if (!(hkey = reg_create_ascii_key( enum_key, gpu->path, 0, NULL ))) return;
if ((subkey = reg_create_ascii_key( hkey, "Device Parameters", 0, NULL ))) { - if (query_reg_ascii_value( subkey, "VideoID", value, sizeof(buffer) ) != sizeof(ctx->gpu.guid) * sizeof(WCHAR)) + if (query_reg_ascii_value( subkey, "VideoID", value, sizeof(buffer) ) != sizeof(gpu->guid) * sizeof(WCHAR)) { GUID guid; uuid_create( &guid ); - snprintf( ctx->gpu.guid, sizeof(ctx->gpu.guid), "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + snprintf( gpu->guid, sizeof(gpu->guid), "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", (unsigned int)guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] ); - TRACE( "created guid %s\n", debugstr_a(ctx->gpu.guid) ); + TRACE( "created guid %s\n", debugstr_a(gpu->guid) ); } else { WCHAR *guidW = (WCHAR *)value->Data; - for (i = 0; i < sizeof(ctx->gpu.guid); i++) ctx->gpu.guid[i] = guidW[i]; - TRACE( "got guid %s\n", debugstr_a(ctx->gpu.guid) ); + for (i = 0; i < sizeof(gpu->guid); i++) gpu->guid[i] = guidW[i]; + TRACE( "got guid %s\n", debugstr_a(gpu->guid) ); } NtClose( subkey ); } @@ -1243,23 +1245,27 @@ static void add_gpu( const char *name, const struct pci_id *pci_id, const GUID * { if (query_reg_value( subkey, NULL, value, sizeof(buffer) ) != sizeof(LUID)) { - NtAllocateLocallyUniqueId( &ctx->gpu.luid ); - TRACE("allocated luid %08x%08x\n", (int)ctx->gpu.luid.HighPart, (int)ctx->gpu.luid.LowPart ); + NtAllocateLocallyUniqueId( &gpu->luid ); + TRACE( "allocated luid %08x%08x\n", (int)gpu->luid.HighPart, (int)gpu->luid.LowPart ); } else { - memcpy( &ctx->gpu.luid, value->Data, sizeof(ctx->gpu.luid) ); - TRACE("got luid %08x%08x\n", (int)ctx->gpu.luid.HighPart, (int)ctx->gpu.luid.LowPart ); + memcpy( &gpu->luid, value->Data, sizeof(gpu->luid) ); + TRACE( "got luid %08x%08x\n", (int)gpu->luid.HighPart, (int)gpu->luid.LowPart ); } NtClose( subkey ); }
NtClose( hkey );
- if (!write_gpu_to_registry( &ctx->gpu, pci_id )) + if (!write_gpu_to_registry( gpu, pci_id )) WARN( "Failed to write gpu to registry\n" ); else + { + if (ctx->gpu) gpu_release( ctx->gpu ); + ctx->gpu = gpu; ctx->gpu_count++; + } }
static BOOL write_source_to_registry( const struct source *source, HKEY *source_key ) @@ -1307,6 +1313,7 @@ static BOOL write_source_to_registry( const struct source *source, HKEY *source_ static void add_source( const char *name, UINT state_flags, void *param ) { struct device_manager_ctx *ctx = param; + struct gpu *gpu = ctx->gpu;
TRACE( "name %s, state_flags %#x\n", name, state_flags );
@@ -1315,19 +1322,19 @@ static void add_source( const char *name, UINT state_flags, void *param ) if (is_virtual_desktop()) state_flags &= ~(DISPLAY_DEVICE_ATTACHED_TO_DESKTOP | DISPLAY_DEVICE_PRIMARY_DEVICE);
memset( &ctx->source, 0, sizeof(ctx->source) ); - ctx->source.gpu = &ctx->gpu; + ctx->source.gpu = gpu; ctx->source.id = ctx->source_count; ctx->source.state_flags = state_flags;
/* Wine specific config key where source settings will be held, symlinked with the logically indexed config key */ snprintf( ctx->source.path, sizeof(ctx->source.path), "%s\%s\Video\%s\Sources\%s", config_keyA, - control_keyA + strlen( "\Registry\Machine" ), ctx->gpu.guid, name ); + control_keyA + strlen( "\Registry\Machine" ), gpu->guid, name );
if (!write_source_to_registry( &ctx->source, &ctx->source_key )) WARN( "Failed to write source to registry\n" ); else { - ctx->gpu.source_count++; + gpu->source_count++; ctx->source_count++; } } @@ -1491,6 +1498,8 @@ static void release_display_manager_ctx( struct device_manager_ctx *ctx ) last_query_display_time = 0; } if (ctx->gpu_count) cleanup_devices(); + + gpu_release( ctx->gpu ); }
static void clear_display_devices(void) @@ -1877,17 +1886,18 @@ static void add_virtual_modes( struct device_manager_ctx *ctx, const DEVMODEW *c static BOOL add_virtual_source( struct device_manager_ctx *ctx ) { DEVMODEW current, initial = ctx->primary, maximum = ctx->primary; + struct gpu *gpu = ctx->gpu; struct source virtual_source = { .state_flags = DISPLAY_DEVICE_ATTACHED_TO_DESKTOP | DISPLAY_DEVICE_PRIMARY_DEVICE | DISPLAY_DEVICE_VGA_COMPATIBLE, .id = ctx->source_count, - .gpu = &ctx->gpu, + .gpu = gpu, }; struct gdi_monitor monitor = {0};
/* Wine specific config key where source settings will be held, symlinked with the logically indexed config key */ snprintf( virtual_source.path, sizeof(virtual_source.path), "%s\%s\Video\%s\Sources\%s", config_keyA, - control_keyA + strlen( "\Registry\Machine" ), virtual_source.gpu->guid, "Virtual" ); + control_keyA + strlen( "\Registry\Machine" ), gpu->guid, "Virtual" );
if (!write_source_to_registry( &virtual_source, &ctx->source_key )) { @@ -1896,7 +1906,7 @@ static BOOL add_virtual_source( struct device_manager_ctx *ctx ) }
ctx->source = virtual_source; - ctx->gpu.source_count++; + gpu->source_count++; ctx->source_count++;
if (!get_default_desktop_size( &initial.dmPelsWidth, &initial.dmPelsHeight ))