From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/sysparams.c | 92 ++++++++++------------------------------- 1 file changed, 21 insertions(+), 71 deletions(-)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index ced9c61db06..6ca180473ba 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -111,6 +111,7 @@ struct source UINT state_flags; UINT monitor_count; UINT mode_count; + DEVMODEW current; DEVMODEW *modes; };
@@ -493,37 +494,9 @@ static BOOL source_set_registry_settings( const struct source *source, const DEV return ret; }
-static BOOL source_get_current_settings( const struct source *source, DEVMODEW *mode ) +static void source_get_current_settings( const struct source *source, DEVMODEW *mode ) { - BOOL is_primary = !!(source->state_flags & DISPLAY_DEVICE_PRIMARY_DEVICE); - WCHAR device_nameW[CCHDEVICENAME]; - char device_name[CCHDEVICENAME]; - HANDLE mutex; - HKEY hkey; - BOOL ret; - - snprintf( device_name, sizeof(device_name), "\\.\DISPLAY%d", source->id + 1 ); - asciiz_to_unicode( device_nameW, device_name ); - - /* use the default implementation in virtual desktop mode */ - if (is_virtual_desktop()) ret = FALSE; - else ret = user_driver->pGetCurrentDisplaySettings( device_nameW, is_primary, mode ); - - if (ret) return TRUE; - - /* default implementation: read current display settings from the registry. */ - - mutex = get_display_device_init_mutex(); - - if (!(hkey = reg_open_ascii_key( config_key, source->path ))) ret = FALSE; - else - { - ret = read_source_mode( hkey, ENUM_CURRENT_SETTINGS, mode ); - NtClose( hkey ); - } - - release_display_device_init_mutex( mutex ); - return ret; + memcpy( &mode->dmFields, &source->current.dmFields, sizeof(*mode) - offsetof(DEVMODEW, dmFields) ); }
static BOOL source_set_current_settings( const struct source *source, const DEVMODEW *mode ) @@ -666,6 +639,10 @@ static BOOL read_source_from_registry( unsigned int index, struct source *source } value = (void *)buffer;
+ /* Cache current display mode */ + if (read_source_mode( hkey, ENUM_CURRENT_SETTINGS, &source->current )) + source->current.dmSize = sizeof(source->current); + /* DeviceID */ size = query_reg_ascii_value( hkey, "GPUID", value, sizeof(buffer) ); NtClose( hkey ); @@ -2733,7 +2710,6 @@ LONG WINAPI NtUserQueryDisplayConfig( UINT32 flags, UINT32 *paths_count, DISPLAY LONG ret; UINT32 output_id, source_mode_index, path_index = 0, mode_index = 0; const LUID *gpu_luid; - DEVMODEW devmode; struct monitor *monitor;
FIXME( "flags %#x, paths_count %p, paths %p, modes_count %p, modes %p, topology_id %p semi-stub\n", @@ -2777,13 +2753,6 @@ LONG WINAPI NtUserQueryDisplayConfig( UINT32 flags, UINT32 *paths_count, DISPLAY gpu_luid = &monitor->source->gpu->luid; output_id = monitor->output_id;
- memset( &devmode, 0, sizeof(devmode) ); - devmode.dmSize = sizeof(devmode); - if (!source_get_current_settings( monitor->source, &devmode )) - { - goto done; - } - if (path_index == *paths_count || mode_index == *modes_count) { ret = ERROR_INSUFFICIENT_BUFFER; @@ -2791,8 +2760,8 @@ LONG WINAPI NtUserQueryDisplayConfig( UINT32 flags, UINT32 *paths_count, DISPLAY }
paths[path_index].flags = DISPLAYCONFIG_PATH_ACTIVE; - set_mode_target_info( &modes[mode_index], gpu_luid, output_id, flags, &devmode ); - set_path_target_info( &paths[path_index].targetInfo, gpu_luid, output_id, mode_index, &devmode ); + set_mode_target_info( &modes[mode_index], gpu_luid, output_id, flags, &monitor->source->current ); + set_path_target_info( &paths[path_index].targetInfo, gpu_luid, output_id, mode_index, &monitor->source->current );
mode_index++; if (mode_index == *modes_count) @@ -2806,7 +2775,7 @@ LONG WINAPI NtUserQueryDisplayConfig( UINT32 flags, UINT32 *paths_count, DISPLAY */ if (!source_mode_exists( modes, mode_index, source_index, &source_mode_index )) { - set_mode_source_info( &modes[mode_index], gpu_luid, source_index, &devmode ); + set_mode_source_info( &modes[mode_index], gpu_luid, source_index, &monitor->source->current ); source_mode_index = mode_index; mode_index++; } @@ -3168,14 +3137,11 @@ static BOOL source_get_full_mode( const struct source *source, const DEVMODEW *d
if (!is_detached_mode( full_mode ) && (!full_mode->dmPelsWidth || !full_mode->dmPelsHeight || !(full_mode->dmFields & DM_POSITION))) { - DEVMODEW current_mode = {.dmSize = sizeof(DEVMODEW)}; - - if (!source_get_current_settings( source, ¤t_mode )) return FALSE; - if (!full_mode->dmPelsWidth) full_mode->dmPelsWidth = current_mode.dmPelsWidth; - if (!full_mode->dmPelsHeight) full_mode->dmPelsHeight = current_mode.dmPelsHeight; + if (!full_mode->dmPelsWidth) full_mode->dmPelsWidth = source->current.dmPelsWidth; + if (!full_mode->dmPelsHeight) full_mode->dmPelsHeight = source->current.dmPelsHeight; if (!(full_mode->dmFields & DM_POSITION)) { - full_mode->dmPosition = current_mode.dmPosition; + full_mode->dmPosition = source->current.dmPosition; full_mode->dmFields |= DM_POSITION; } } @@ -3195,7 +3161,6 @@ static DEVMODEW *get_display_settings( struct source *target, const DEVMODEW *de { DEVMODEW *mode, *displays; struct source *source; - BOOL ret;
/* allocate an extra mode for easier iteration */ if (!(displays = calloc( list_count( &sources ) + 1, sizeof(DEVMODEW) ))) return NULL; @@ -3210,9 +3175,8 @@ static DEVMODEW *get_display_settings( struct source *target, const DEVMODEW *de memcpy( &mode->dmFields, &devmode->dmFields, devmode->dmSize - offsetof(DEVMODEW, dmFields) ); else { - if (!target) ret = source_get_registry_settings( source, mode ); - else ret = source_get_current_settings( source, mode ); - if (!ret) + if (target) source_get_current_settings( source, mode ); + else if (!source_get_registry_settings( source, mode )) { free( displays ); return NULL; @@ -3417,13 +3381,12 @@ static BOOL all_detached_settings( const DEVMODEW *displays ) static BOOL get_primary_source_mode( DEVMODEW *mode ) { struct source *primary; - BOOL ret;
if (!(primary = find_source( NULL ))) return FALSE; - ret = source_get_current_settings( primary, mode ); + source_get_current_settings( primary, mode ); source_release( primary );
- return ret; + return TRUE; }
static void display_mode_changed( BOOL broadcast ) @@ -3558,19 +3521,12 @@ LONG WINAPI NtUserChangeDisplaySettings( UNICODE_STRING *devname, DEVMODEW *devm
static BOOL source_enum_display_settings( const struct source *source, UINT index, DEVMODEW *devmode, UINT flags ) { - DEVMODEW current_mode = {.dmSize = sizeof(DEVMODEW)}; const DEVMODEW *source_mode;
- if (!(flags & EDS_ROTATEDMODE) && !source_get_current_settings( source, ¤t_mode )) - { - WARN( "Failed to query current display mode for EDS_ROTATEDMODE flag.\n" ); - return FALSE; - } - for (source_mode = source->modes; source_mode->dmSize; source_mode = NEXT_DEVMODEW(source_mode)) { if (!(flags & EDS_ROTATEDMODE) && (source_mode->dmFields & DM_DISPLAYORIENTATION) && - source_mode->dmDisplayOrientation != current_mode.dmDisplayOrientation) + source_mode->dmDisplayOrientation != source->current.dmDisplayOrientation) continue; if (!(flags & EDS_RAWMODE) && (source_mode->dmFields & DM_DISPLAYFLAGS) && (source_mode->dmDisplayFlags & WINE_DM_UNSUPPORTED)) @@ -3595,7 +3551,7 @@ BOOL WINAPI NtUserEnumDisplaySettings( UNICODE_STRING *device, DWORD index, DEVM { static const WCHAR wine_display_driverW[] = {'W','i','n','e',' ','D','i','s','p','l','a','y',' ','D','r','i','v','e','r',0}; struct source *source; - BOOL ret; + BOOL ret = TRUE;
TRACE( "device %s, index %#x, devmode %p, flags %#x\n", debugstr_us(device), (int)index, devmode, (int)flags ); @@ -3609,7 +3565,7 @@ BOOL WINAPI NtUserEnumDisplaySettings( UNICODE_STRING *device, DWORD index, DEVM devmode->dmDriverExtra = 0;
if (index == ENUM_REGISTRY_SETTINGS) ret = source_get_registry_settings( source, devmode ); - else if (index == ENUM_CURRENT_SETTINGS) ret = source_get_current_settings( source, devmode ); + else if (index == ENUM_CURRENT_SETTINGS) source_get_current_settings( source, devmode ); else ret = source_enum_display_settings( source, index, devmode, flags ); source_release( source );
@@ -3667,13 +3623,7 @@ INT get_display_depth( UNICODE_STRING *name ) /* use the default implementation in virtual desktop mode */ if (is_virtual_desktop()) depth = -1; else depth = user_driver->pGetDisplayDepth( device_nameW, is_primary ); - - if (depth < 0) - { - DEVMODEW current_mode = {.dmSize = sizeof(DEVMODEW)}; - if (!source_get_current_settings( source, ¤t_mode )) depth = 32; - else depth = current_mode.dmBitsPerPel; - } + if (depth < 0) depth = source->current.dmBitsPerPel;
unlock_display_devices(); return depth;