Commit d9a4bdfd authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

win32u: Move reading mode from registry out of graphics drivers.

parent 566dd3af
......@@ -169,6 +169,15 @@ static const WCHAR displayW[] = {'D','i','s','p','l','a','y',0};
static const WCHAR monitorW[] = {'M','o','n','i','t','o','r',0};
static const WCHAR yesW[] = {'Y','e','s',0};
static const WCHAR noW[] = {'N','o',0};
static const WCHAR bits_per_pelW[] = {'B','i','t','s','P','e','r','P','e','l',0};
static const WCHAR x_resolutionW[] = {'X','R','e','s','o','l','u','t','i','o','n',0};
static const WCHAR y_resolutionW[] = {'Y','R','e','s','o','l','u','t','i','o','n',0};
static const WCHAR v_refreshW[] = {'V','R','e','f','r','e','s','h',0};
static const WCHAR flagsW[] = {'F','l','a','g','s',0};
static const WCHAR x_panningW[] = {'X','P','a','n','n','i','n','g',0};
static const WCHAR y_panningW[] = {'Y','P','a','n','n','i','n','g',0};
static const WCHAR orientationW[] = {'O','r','i','e','n','t','a','t','i','o','n',0};
static const WCHAR fixed_outputW[] = {'F','i','x','e','d','O','u','t','p','u','t',0};
static const char guid_devclass_displayA[] = "{4D36E968-E325-11CE-BFC1-08002BE10318}";
static const WCHAR guid_devclass_displayW[] =
......@@ -411,6 +420,59 @@ static void release_display_device_init_mutex( HANDLE mutex )
NtClose( mutex );
}
static BOOL read_adapter_mode( HKEY adapter_key, DEVMODEW *mode )
{
static const WCHAR default_settingsW[] = {'D','e','f','a','u','l','t','S','e','t','t','i','n','g','s','.',0};
char value_buf[offsetof(KEY_VALUE_PARTIAL_INFORMATION, Data[sizeof(DWORD)])];
KEY_VALUE_PARTIAL_INFORMATION *value = (void *)value_buf;
WCHAR bufferW[MAX_PATH];
#define query_mode_field( name, field, flag ) \
do \
{ \
lstrcpyW( bufferW, default_settingsW ); \
lstrcatW( bufferW, (name) ); \
if (!query_reg_value( adapter_key, bufferW, value, sizeof(value_buf) ) || \
value->Type != REG_DWORD) return FALSE; \
mode->field = *(const DWORD *)value->Data; \
mode->dmFields |= (flag); \
} while (0)
query_mode_field( bits_per_pelW, dmBitsPerPel, DM_BITSPERPEL );
query_mode_field( x_resolutionW, dmPelsWidth, DM_PELSWIDTH );
query_mode_field( y_resolutionW, dmPelsHeight, DM_PELSHEIGHT );
query_mode_field( v_refreshW, dmDisplayFrequency, DM_DISPLAYFREQUENCY );
query_mode_field( flagsW, dmDisplayFlags, DM_DISPLAYFLAGS );
query_mode_field( x_panningW, dmPosition.x, DM_POSITION );
query_mode_field( y_panningW, dmPosition.y, DM_POSITION );
query_mode_field( orientationW, dmDisplayOrientation, DM_DISPLAYORIENTATION );
query_mode_field( fixed_outputW, dmDisplayFixedOutput, 0 );
#undef query_mode_field
return TRUE;
}
static BOOL read_registry_settings( const WCHAR *adapter_path, DEVMODEW *mode )
{
BOOL ret = FALSE;
HANDLE mutex;
HKEY hkey;
mutex = get_display_device_init_mutex();
if (!config_key && !(config_key = reg_open_key( NULL, config_keyW, sizeof(config_keyW) ))) ret = FALSE;
else if (!(hkey = reg_open_key( config_key, adapter_path, lstrlenW( adapter_path ) * sizeof(WCHAR) ))) ret = FALSE;
else
{
ret = read_adapter_mode( hkey, mode );
NtClose( hkey );
}
release_display_device_init_mutex( mutex );
return ret;
}
static BOOL read_display_adapter_settings( unsigned int index, struct adapter *info )
{
char buffer[4096];
......@@ -1840,7 +1902,7 @@ static BOOL is_detached_mode( const DEVMODEW *mode )
LONG WINAPI NtUserChangeDisplaySettings( UNICODE_STRING *devname, DEVMODEW *devmode, HWND hwnd,
DWORD flags, void *lparam )
{
WCHAR device_name[CCHDEVICENAME];
WCHAR device_name[CCHDEVICENAME], adapter_path[MAX_PATH];
struct adapter *adapter;
BOOL def_mode = TRUE;
DEVMODEW dm;
......@@ -1858,7 +1920,11 @@ LONG WINAPI NtUserChangeDisplaySettings( UNICODE_STRING *devname, DEVMODEW *devm
}
if (!lock_display_devices()) return DISP_CHANGE_FAILED;
if ((adapter = find_adapter( devname ))) lstrcpyW( device_name, adapter->dev.device_name );
if ((adapter = find_adapter( devname )))
{
lstrcpyW( device_name, adapter->dev.device_name );
lstrcpyW( adapter_path, adapter->config_key );
}
unlock_display_devices();
if (!adapter)
{
......@@ -1885,7 +1951,7 @@ LONG WINAPI NtUserChangeDisplaySettings( UNICODE_STRING *devname, DEVMODEW *devm
{
memset( &dm, 0, sizeof(dm) );
dm.dmSize = sizeof(dm);
if (!NtUserEnumDisplaySettings( devname, ENUM_REGISTRY_SETTINGS, &dm, 0 ))
if (!read_registry_settings( adapter_path, &dm ))
{
ERR( "Default mode not found!\n" );
return DISP_CHANGE_BADMODE;
......@@ -1929,14 +1995,18 @@ LONG WINAPI NtUserChangeDisplaySettings( UNICODE_STRING *devname, DEVMODEW *devm
BOOL WINAPI NtUserEnumDisplaySettings( UNICODE_STRING *device, DWORD index, DEVMODEW *devmode, DWORD flags )
{
static const WCHAR wine_display_driverW[] = {'W','i','n','e',' ','D','i','s','p','l','a','y',' ','D','r','i','v','e','r',0};
WCHAR device_name[CCHDEVICENAME];
WCHAR device_name[CCHDEVICENAME], adapter_path[MAX_PATH];
struct adapter *adapter;
BOOL ret;
TRACE( "device %s, index %#x, devmode %p, flags %#x\n", debugstr_us(device), index, devmode, flags );
if (!lock_display_devices()) return FALSE;
if ((adapter = find_adapter( device ))) lstrcpyW( device_name, adapter->dev.device_name );
if ((adapter = find_adapter( device )))
{
lstrcpyW( device_name, adapter->dev.device_name );
lstrcpyW( adapter_path, adapter->config_key );
}
unlock_display_devices();
if (!adapter)
{
......@@ -1950,7 +2020,8 @@ BOOL WINAPI NtUserEnumDisplaySettings( UNICODE_STRING *device, DWORD index, DEVM
devmode->dmSize = offsetof(DEVMODEW, dmICMMethod);
memset( &devmode->dmDriverExtra, 0, devmode->dmSize - offsetof(DEVMODEW, dmDriverExtra) );
ret = user_driver->pEnumDisplaySettingsEx( device_name, index, devmode, flags );
if (index == ENUM_REGISTRY_SETTINGS) ret = read_registry_settings( adapter_path, devmode );
else ret = user_driver->pEnumDisplaySettingsEx( device_name, index, devmode, flags );
if (!ret) WARN( "Failed to query %s display settings.\n", debugstr_w(device_name) );
else TRACE( "position %dx%d, resolution %ux%u, frequency %u, depth %u, orientation %#x.\n",
......
......@@ -310,7 +310,7 @@ BOOL ANDROID_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmode, D
devmode->u1.s2.dmDisplayOrientation = 0;
devmode->u1.s2.dmDisplayFixedOutput = 0;
if (n == ENUM_CURRENT_SETTINGS || n == ENUM_REGISTRY_SETTINGS) n = 0;
if (n == ENUM_CURRENT_SETTINGS) n = 0;
if (n == 0)
{
devmode->dmPelsWidth = screen_width;
......
......@@ -128,60 +128,6 @@ static HKEY get_display_device_reg_key(const WCHAR *device_name)
}
static BOOL query_display_setting(HKEY hkey, const char *name, DWORD *ret)
{
char buffer[1024];
WCHAR nameW[128];
KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer;
asciiz_to_unicode(nameW, name);
if (query_reg_value(hkey, nameW, value, sizeof(buffer)) != sizeof(DWORD) ||
value->Type != REG_DWORD)
return FALSE;
*ret = *(DWORD *)value->Data;
return TRUE;
}
static BOOL read_registry_settings(const WCHAR *device_name, DEVMODEW *dm)
{
HANDLE mutex;
HKEY hkey;
BOOL ret = TRUE;
dm->dmFields = 0;
mutex = get_display_device_init_mutex();
if (!(hkey = get_display_device_reg_key(device_name)))
{
release_display_device_init_mutex(mutex);
return FALSE;
}
ret &= query_display_setting(hkey, "DefaultSettings.BitsPerPel", &dm->dmBitsPerPel);
dm->dmFields |= DM_BITSPERPEL;
ret &= query_display_setting(hkey, "DefaultSettings.XResolution", &dm->dmPelsWidth);
dm->dmFields |= DM_PELSWIDTH;
ret &= query_display_setting(hkey, "DefaultSettings.YResolution", &dm->dmPelsHeight);
dm->dmFields |= DM_PELSHEIGHT;
ret &= query_display_setting(hkey, "DefaultSettings.VRefresh", &dm->dmDisplayFrequency);
dm->dmFields |= DM_DISPLAYFREQUENCY;
ret &= query_display_setting(hkey, "DefaultSettings.Flags", &dm->dmDisplayFlags);
dm->dmFields |= DM_DISPLAYFLAGS;
ret &= query_display_setting(hkey, "DefaultSettings.XPanning", (DWORD *)&dm->dmPosition.x);
ret &= query_display_setting(hkey, "DefaultSettings.YPanning", (DWORD *)&dm->dmPosition.y);
dm->dmFields |= DM_POSITION;
ret &= query_display_setting(hkey, "DefaultSettings.Orientation", &dm->dmDisplayOrientation);
dm->dmFields |= DM_DISPLAYORIENTATION;
ret &= query_display_setting(hkey, "DefaultSettings.FixedOutput", &dm->dmDisplayFixedOutput);
NtClose(hkey);
release_display_device_init_mutex(mutex);
return ret;
}
static BOOL set_setting_value(HKEY hkey, const char *name, DWORD val)
{
WCHAR nameW[128];
......@@ -1056,12 +1002,6 @@ BOOL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode, DEVMODEW *devmode
init_original_display_mode();
if (mode == ENUM_REGISTRY_SETTINGS)
{
TRACE("mode %d (registry) -- getting default mode\n", mode);
return read_registry_settings(devname, devmode);
}
if (macdrv_get_displays(&displays, &num_displays))
goto failed;
......
......@@ -257,58 +257,6 @@ static HKEY get_display_device_reg_key( const WCHAR *device_name )
return reg_open_key( NULL, buffer, lstrlenW(buffer) * sizeof(WCHAR) );
}
static BOOL query_display_setting( HKEY hkey, const char *name, DWORD *ret )
{
char buffer[1024];
WCHAR nameW[128];
KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer;
asciiz_to_unicode( nameW, name );
if (query_reg_value( hkey, nameW, value, sizeof(buffer) ) != sizeof(DWORD) ||
value->Type != REG_DWORD)
return FALSE;
*ret = *(DWORD *)value->Data;
return TRUE;
}
static BOOL read_registry_settings(const WCHAR *device_name, DEVMODEW *dm)
{
HANDLE mutex;
HKEY hkey;
BOOL ret = TRUE;
dm->dmFields = 0;
mutex = get_display_device_init_mutex();
if (!(hkey = get_display_device_reg_key( device_name )))
{
release_display_device_init_mutex(mutex);
return FALSE;
}
ret &= query_display_setting( hkey, "DefaultSettings.BitsPerPel", &dm->dmBitsPerPel );
dm->dmFields |= DM_BITSPERPEL;
ret &= query_display_setting( hkey, "DefaultSettings.XResolution", &dm->dmPelsWidth );
dm->dmFields |= DM_PELSWIDTH;
ret &= query_display_setting( hkey, "DefaultSettings.YResolution", &dm->dmPelsHeight );
dm->dmFields |= DM_PELSHEIGHT;
ret &= query_display_setting( hkey, "DefaultSettings.VRefresh", &dm->dmDisplayFrequency );
dm->dmFields |= DM_DISPLAYFREQUENCY;
ret &= query_display_setting( hkey, "DefaultSettings.Flags", &dm->dmDisplayFlags );
dm->dmFields |= DM_DISPLAYFLAGS;
ret &= query_display_setting( hkey, "DefaultSettings.XPanning", (DWORD *)&dm->dmPosition.x );
ret &= query_display_setting( hkey, "DefaultSettings.YPanning", (DWORD *)&dm->dmPosition.y );
dm->dmFields |= DM_POSITION;
ret &= query_display_setting( hkey, "DefaultSettings.Orientation", &dm->dmDisplayOrientation );
dm->dmFields |= DM_DISPLAYORIENTATION;
ret &= query_display_setting( hkey, "DefaultSettings.FixedOutput", &dm->dmDisplayFixedOutput );
NtClose( hkey );
release_display_device_init_mutex(mutex);
return ret;
}
static BOOL set_setting_value( HKEY hkey, const char *name, DWORD val )
{
WCHAR nameW[128];
......@@ -468,16 +416,6 @@ BOOL X11DRV_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmode, DW
UINT mode_count;
ULONG_PTR id;
if (n == ENUM_REGISTRY_SETTINGS)
{
if (!read_registry_settings(name, devmode))
{
ERR("Failed to get %s registry display settings.\n", wine_dbgstr_w(name));
return FALSE;
}
return TRUE;
}
if (n == ENUM_CURRENT_SETTINGS)
{
if (!settings_handler.get_id( name, &id ) || !settings_handler.get_current_mode( id, &mode ))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment