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

win32u: Move enumeration of available modes out of graphics drivers.

parent 6d504174
......@@ -759,11 +759,6 @@ static LONG nulldrv_ChangeDisplaySettings( LPDEVMODEW displays, HWND hwnd,
return DISP_CHANGE_FAILED;
}
static BOOL nulldrv_EnumDisplaySettingsEx( LPCWSTR name, DWORD num, LPDEVMODEW mode, DWORD flags )
{
return FALSE;
}
static BOOL nulldrv_GetCurrentDisplaySettings( LPCWSTR name, LPDEVMODEW mode )
{
return FALSE;
......@@ -1077,11 +1072,6 @@ static LONG loaderdrv_ChangeDisplaySettings( LPDEVMODEW displays, HWND hwnd,
return load_driver()->pChangeDisplaySettings( displays, hwnd, flags, lparam );
}
static BOOL loaderdrv_EnumDisplaySettingsEx( LPCWSTR name, DWORD num, LPDEVMODEW mode, DWORD flags )
{
return load_driver()->pEnumDisplaySettingsEx( name, num, mode, flags );
}
static BOOL loaderdrv_GetCurrentDisplaySettings( LPCWSTR name, LPDEVMODEW mode )
{
return load_driver()->pGetCurrentDisplaySettings( name, mode );
......@@ -1188,7 +1178,6 @@ static const struct user_driver_funcs lazy_load_driver =
loaderdrv_UpdateClipboard,
/* display modes */
loaderdrv_ChangeDisplaySettings,
loaderdrv_EnumDisplaySettingsEx,
loaderdrv_GetCurrentDisplaySettings,
loaderdrv_UpdateDisplayDevices,
/* windowing functions */
......@@ -1264,7 +1253,6 @@ void __wine_set_user_driver( const struct user_driver_funcs *funcs, UINT version
SET_USER_FUNC(ClipboardWindowProc);
SET_USER_FUNC(UpdateClipboard);
SET_USER_FUNC(ChangeDisplaySettings);
SET_USER_FUNC(EnumDisplaySettingsEx);
SET_USER_FUNC(GetCurrentDisplaySettings);
SET_USER_FUNC(UpdateDisplayDevices);
SET_USER_FUNC(CreateDesktopWindow);
......
......@@ -2498,6 +2498,39 @@ LONG WINAPI NtUserChangeDisplaySettings( UNICODE_STRING *devname, DEVMODEW *devm
return ret;
}
static BOOL adapter_enum_display_settings( const struct adapter *adapter, DWORD index, DEVMODEW *devmode, DWORD flags )
{
DEVMODEW current_mode = {.dmSize = sizeof(DEVMODEW)};
const DEVMODEW *adapter_mode;
if (!(flags & EDS_ROTATEDMODE) && !user_driver->pGetCurrentDisplaySettings( adapter->dev.device_name, &current_mode ))
{
WARN( "Failed to query current display mode for EDS_ROTATEDMODE flag.\n" );
return FALSE;
}
for (adapter_mode = adapter->modes; adapter_mode->dmSize; adapter_mode = NEXT_DEVMODEW(adapter_mode))
{
if (!(flags & EDS_ROTATEDMODE) && (adapter_mode->dmFields & DM_DISPLAYORIENTATION) &&
adapter_mode->dmDisplayOrientation != current_mode.dmDisplayOrientation)
continue;
if (!(flags & EDS_RAWMODE) && (adapter_mode->dmFields & DM_DISPLAYFLAGS) &&
(adapter_mode->dmDisplayFlags & WINE_DM_UNSUPPORTED))
continue;
if (!index--)
{
memcpy( &devmode->dmFields, &adapter_mode->dmFields, devmode->dmSize - FIELD_OFFSET(DEVMODEW, dmFields) );
devmode->dmDisplayFlags &= ~WINE_DM_UNSUPPORTED;
return TRUE;
}
}
WARN( "device %s, index %#x, flags %#x display mode not found.\n",
debugstr_w( adapter->dev.device_name ), index, flags );
RtlSetLastWin32Error( ERROR_NO_MORE_FILES );
return FALSE;
}
/***********************************************************************
* NtUserEnumDisplaySettings (win32u.@)
*/
......@@ -2522,15 +2555,13 @@ BOOL WINAPI NtUserEnumDisplaySettings( UNICODE_STRING *device, DWORD index, DEVM
devmode->dmSpecVersion = DM_SPECVERSION;
devmode->dmDriverVersion = DM_SPECVERSION;
devmode->dmSize = offsetof(DEVMODEW, dmICMMethod);
memset( &devmode->dmDriverExtra, 0, devmode->dmSize - offsetof(DEVMODEW, dmDriverExtra) );
devmode->dmDriverExtra = 0;
if (index == ENUM_REGISTRY_SETTINGS) ret = adapter_get_registry_settings( adapter, devmode );
else if (index != ENUM_CURRENT_SETTINGS) ret = user_driver->pEnumDisplaySettingsEx( adapter->dev.device_name, index, devmode, flags );
else ret = user_driver->pGetCurrentDisplaySettings( adapter->dev.device_name, devmode );
else if (index == ENUM_CURRENT_SETTINGS) ret = user_driver->pGetCurrentDisplaySettings( adapter->dev.device_name, devmode );
else ret = adapter_enum_display_settings( adapter, index, devmode, flags );
adapter_release( adapter );
devmode->dmDisplayFlags &= ~WINE_DM_UNSUPPORTED;
if (!ret) WARN( "Failed to query %s display settings.\n", debugstr_us(device) );
else TRACE( "position %dx%d, resolution %ux%u, frequency %u, depth %u, orientation %#x.\n",
devmode->dmPosition.x, devmode->dmPosition.y, devmode->dmPelsWidth, devmode->dmPelsHeight,
......
......@@ -304,36 +304,6 @@ BOOL ANDROID_UpdateDisplayDevices( const struct gdi_device_manager *device_manag
/***********************************************************************
* ANDROID_EnumDisplaySettingsEx
*/
BOOL ANDROID_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmode, DWORD flags )
{
if (n > 0)
{
TRACE( "mode %d -- not present\n", n );
RtlSetLastWin32Error( ERROR_NO_MORE_FILES );
return FALSE;
}
devmode->u2.dmDisplayFlags = 0;
devmode->u1.s2.dmPosition.x = 0;
devmode->u1.s2.dmPosition.y = 0;
devmode->u1.s2.dmDisplayOrientation = 0;
devmode->u1.s2.dmDisplayFixedOutput = 0;
devmode->dmPelsWidth = screen_width;
devmode->dmPelsHeight = screen_height;
devmode->dmBitsPerPel = screen_bpp;
devmode->dmDisplayFrequency = 60;
devmode->dmFields = DM_DISPLAYORIENTATION | DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL |
DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY;
TRACE( "mode %d -- %dx%d %d bpp @%d Hz\n", n,
devmode->dmPelsWidth, devmode->dmPelsHeight,
devmode->dmBitsPerPel, devmode->dmDisplayFrequency );
return TRUE;
}
/***********************************************************************
* ANDROID_GetCurrentDisplaySettings
*/
BOOL ANDROID_GetCurrentDisplaySettings( LPCWSTR name, LPDEVMODEW devmode )
......@@ -377,7 +347,6 @@ static const struct user_driver_funcs android_drv_funcs =
.pVkKeyScanEx = ANDROID_VkKeyScanEx,
.pSetCursor = ANDROID_SetCursor,
.pChangeDisplaySettings = ANDROID_ChangeDisplaySettings,
.pEnumDisplaySettingsEx = ANDROID_EnumDisplaySettingsEx,
.pGetCurrentDisplaySettings = ANDROID_GetCurrentDisplaySettings,
.pUpdateDisplayDevices = ANDROID_UpdateDisplayDevices,
.pCreateWindow = ANDROID_CreateWindow,
......
......@@ -51,10 +51,6 @@ static const WCHAR initial_mode_keyW[] = {'I','n','i','t','i','a','l',' ','D','i
' ','M','o','d','e'};
static const WCHAR pixelencodingW[] = {'P','i','x','e','l','E','n','c','o','d','i','n','g',0};
static CFArrayRef cached_modes;
static DWORD cached_modes_flags;
static CGDirectDisplayID cached_modes_display_id;
static BOOL cached_modes_has_8bpp, cached_modes_has_16bpp;
static int cached_default_mode_bpp;
static pthread_mutex_t cached_modes_mutex = PTHREAD_MUTEX_INITIALIZER;
......@@ -937,164 +933,6 @@ static DEVMODEW *display_get_modes(CGDirectDisplayID display_id, int *modes_coun
}
/***********************************************************************
* EnumDisplaySettingsEx (MACDRV.@)
*
*/
BOOL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode, LPDEVMODEW devmode, DWORD flags)
{
struct macdrv_display *displays = NULL;
int num_displays;
CGDisplayModeRef display_mode;
int display_mode_bpp, display_idx;
BOOL synthesized = FALSE;
CGDirectDisplayID display_id;
DWORD count, i;
WCHAR *end;
TRACE("%s, %u, %p + %hu, %08x\n", debugstr_w(devname), mode, devmode, devmode->dmSize, flags);
init_original_display_mode();
if (macdrv_get_displays(&displays, &num_displays))
goto failed;
display_idx = wcstol(devname + 11, &end, 10) - 1;
if (display_idx >= num_displays)
{
macdrv_free_displays(displays);
return FALSE;
}
display_id = displays[display_idx].displayID;
pthread_mutex_lock(&cached_modes_mutex);
if (mode == 0 || !cached_modes || flags != cached_modes_flags || display_id != cached_modes_display_id)
{
if (cached_modes) CFRelease(cached_modes);
cached_modes = copy_display_modes(display_id, (flags & EDS_RAWMODE) != 0);
cached_modes_has_8bpp = cached_modes_has_16bpp = FALSE;
cached_modes_display_id = display_id;
cached_modes_flags = flags;
if (cached_modes)
{
count = CFArrayGetCount(cached_modes);
for (i = 0; i < count && !(cached_modes_has_8bpp && cached_modes_has_16bpp); i++)
{
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(cached_modes, i);
int bpp = display_mode_bits_per_pixel(mode);
if (bpp == 8)
cached_modes_has_8bpp = TRUE;
else if (bpp == 16)
cached_modes_has_16bpp = TRUE;
}
}
}
display_mode = NULL;
if (cached_modes)
{
int default_bpp;
DWORD seen_modes = 0;
count = CFArrayGetCount(cached_modes);
for (i = 0; i < count; i++)
{
CGDisplayModeRef candidate = (CGDisplayModeRef)CFArrayGetValueAtIndex(cached_modes, i);
seen_modes++;
if (seen_modes > mode)
{
display_mode = (CGDisplayModeRef)CFRetain(candidate);
display_mode_bpp = display_mode_bits_per_pixel(display_mode);
break;
}
}
default_bpp = get_default_bpp();
/* If all the real modes are exhausted, synthesize lower bpp modes. */
if (!display_mode && (!cached_modes_has_16bpp || !cached_modes_has_8bpp))
{
/* We want to synthesize higher depths first. */
int synth_bpps[] = { cached_modes_has_16bpp ? 0 : 16, cached_modes_has_8bpp ? 0 : 8 };
size_t synth_bpp_idx;
for (synth_bpp_idx = 0; synth_bpp_idx < 2; synth_bpp_idx++)
{
int synth_bpp = synth_bpps[synth_bpp_idx];
if (synth_bpp == 0)
continue;
for (i = 0; i < count; i++)
{
CGDisplayModeRef candidate = (CGDisplayModeRef)CFArrayGetValueAtIndex(cached_modes, i);
/* We only synthesize modes from those having the default bpp. */
if (display_mode_bits_per_pixel(candidate) != default_bpp)
continue;
seen_modes++;
if (seen_modes > mode)
{
display_mode = (CGDisplayModeRef)CFRetain(candidate);
display_mode_bpp = synth_bpp;
synthesized = TRUE;
break;
}
}
if (display_mode)
break;
}
}
}
pthread_mutex_unlock(&cached_modes_mutex);
if (!display_mode)
goto failed;
display_mode_to_devmode(display_id, display_mode, devmode);
devmode->dmBitsPerPel = display_mode_bpp;
if (devmode->dmBitsPerPel)
devmode->dmFields |= DM_BITSPERPEL;
if (retina_enabled)
{
struct display_mode_descriptor* desc = create_original_display_mode_descriptor(display_id);
if (display_mode_matches_descriptor(display_mode, desc))
{
devmode->dmPelsWidth *= 2;
devmode->dmPelsHeight *= 2;
}
free_display_mode_descriptor(desc);
}
CFRelease(display_mode);
macdrv_free_displays(displays);
TRACE("mode %d -- %dx%dx%dbpp @%d Hz", mode,
devmode->dmPelsWidth, devmode->dmPelsHeight, devmode->dmBitsPerPel,
devmode->dmDisplayFrequency);
if (devmode->dmDisplayOrientation)
TRACE(" rotated %u degrees", devmode->dmDisplayOrientation * 90);
if (devmode->dmDisplayFixedOutput == DMDFO_STRETCH)
TRACE(" stretched");
if (devmode->dmDisplayFlags & DM_INTERLACED)
TRACE(" interlaced");
if (synthesized)
TRACE(" (synthesized)");
TRACE("\n");
return TRUE;
failed:
TRACE("mode %d -- not present\n", mode);
if (displays) macdrv_free_displays(displays);
RtlSetLastWin32Error(ERROR_NO_MORE_FILES);
return FALSE;
}
/***********************************************************************
* GetCurrentDisplaySettings (MACDRV.@)
*
*/
......
......@@ -275,7 +275,6 @@ static const struct user_driver_funcs macdrv_funcs =
.pDesktopWindowProc = macdrv_DesktopWindowProc,
.pDestroyCursorIcon = macdrv_DestroyCursorIcon,
.pDestroyWindow = macdrv_DestroyWindow,
.pEnumDisplaySettingsEx = macdrv_EnumDisplaySettingsEx,
.pGetCurrentDisplaySettings = macdrv_GetCurrentDisplaySettings,
.pUpdateDisplayDevices = macdrv_UpdateDisplayDevices,
.pGetCursorPos = macdrv_GetCursorPos,
......
......@@ -124,8 +124,6 @@ static inline struct macdrv_thread_data *macdrv_thread_data(void)
extern BOOL macdrv_ActivateKeyboardLayout(HKL hkl, UINT flags) DECLSPEC_HIDDEN;
extern void macdrv_Beep(void) DECLSPEC_HIDDEN;
extern LONG macdrv_ChangeDisplaySettings(LPDEVMODEW displays, HWND hwnd, DWORD flags, LPVOID lpvoid) DECLSPEC_HIDDEN;
extern BOOL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode,
LPDEVMODEW devmode, DWORD flags) DECLSPEC_HIDDEN;
extern BOOL macdrv_GetCurrentDisplaySettings(LPCWSTR name, LPDEVMODEW devmode) DECLSPEC_HIDDEN;
extern LRESULT macdrv_ClipboardWindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) DECLSPEC_HIDDEN;
extern BOOL macdrv_UpdateDisplayDevices( const struct gdi_device_manager *device_manager,
......
......@@ -51,12 +51,6 @@ static const unsigned int depths_24[] = {8, 16, 24};
static const unsigned int depths_32[] = {8, 16, 32};
const unsigned int *depths;
/* Cached display modes for a device, protected by modes_section */
static WCHAR cached_device_name[CCHDEVICENAME];
static DWORD cached_flags;
static DEVMODEW *cached_modes;
static UINT cached_mode_count;
static pthread_mutex_t settings_mutex = PTHREAD_MUTEX_INITIALIZER;
void X11DRV_Settings_SetHandler(const struct x11drv_settings_handler *new_handler)
......@@ -220,54 +214,6 @@ BOOL get_primary_adapter(WCHAR *name)
return FALSE;
}
static int mode_compare(const void *p1, const void *p2)
{
DWORD a_width, a_height, b_width, b_height;
const DEVMODEW *a = p1, *b = p2;
/* Use the width and height in landscape mode for comparison */
if (a->dmDisplayOrientation == DMDO_DEFAULT || a->dmDisplayOrientation == DMDO_180)
{
a_width = a->dmPelsWidth;
a_height = a->dmPelsHeight;
}
else
{
a_width = a->dmPelsHeight;
a_height = a->dmPelsWidth;
}
if (b->dmDisplayOrientation == DMDO_DEFAULT || b->dmDisplayOrientation == DMDO_180)
{
b_width = b->dmPelsWidth;
b_height = b->dmPelsHeight;
}
else
{
b_width = b->dmPelsHeight;
b_height = b->dmPelsWidth;
}
/* Depth in descending order */
if (a->dmBitsPerPel != b->dmBitsPerPel)
return b->dmBitsPerPel - a->dmBitsPerPel;
/* Width in ascending order */
if (a_width != b_width)
return a_width - b_width;
/* Height in ascending order */
if (a_height != b_height)
return a_height - b_height;
/* Frequency in descending order */
if (a->dmDisplayFrequency != b->dmDisplayFrequency)
return b->dmDisplayFrequency - a->dmDisplayFrequency;
/* Orientation in ascending order */
return a->dmDisplayOrientation - b->dmDisplayOrientation;
}
static void set_display_depth(ULONG_PTR display_id, DWORD depth)
{
struct x11drv_display_depth *display_depth;
......@@ -317,51 +263,6 @@ static DWORD get_display_depth(ULONG_PTR display_id)
}
/***********************************************************************
* EnumDisplaySettingsEx (X11DRV.@)
*
*/
BOOL X11DRV_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmode, DWORD flags)
{
DEVMODEW *modes, mode;
UINT mode_count;
ULONG_PTR id;
pthread_mutex_lock( &settings_mutex );
if (n == 0 || wcsicmp(cached_device_name, name) || cached_flags != flags)
{
if (!settings_handler.get_id(name, &id) || !settings_handler.get_modes(id, flags, &modes, &mode_count))
{
ERR("Failed to get %s supported display modes.\n", wine_dbgstr_w(name));
pthread_mutex_unlock( &settings_mutex );
return FALSE;
}
qsort(modes, mode_count, sizeof(*modes) + modes[0].dmDriverExtra, mode_compare);
if (cached_modes)
settings_handler.free_modes(cached_modes);
lstrcpyW(cached_device_name, name);
cached_flags = flags;
cached_modes = modes;
cached_mode_count = mode_count;
}
if (n >= cached_mode_count)
{
pthread_mutex_unlock( &settings_mutex );
WARN("handler:%s device:%s mode index:%#x not found.\n", settings_handler.name, wine_dbgstr_w(name), n);
RtlSetLastWin32Error( ERROR_NO_MORE_FILES );
return FALSE;
}
mode = *(DEVMODEW *)((BYTE *)cached_modes + (sizeof(*cached_modes) + cached_modes[0].dmDriverExtra) * n);
pthread_mutex_unlock( &settings_mutex );
memcpy( &devmode->dmFields, &mode.dmFields, devmode->dmSize - offsetof(DEVMODEW, dmFields) );
return TRUE;
}
/***********************************************************************
* GetCurrentDisplaySettings (X11DRV.@)
*
*/
......
......@@ -404,7 +404,6 @@ static const struct user_driver_funcs x11drv_funcs =
.pSetCursorPos = X11DRV_SetCursorPos,
.pClipCursor = X11DRV_ClipCursor,
.pChangeDisplaySettings = X11DRV_ChangeDisplaySettings,
.pEnumDisplaySettingsEx = X11DRV_EnumDisplaySettingsEx,
.pGetCurrentDisplaySettings = X11DRV_GetCurrentDisplaySettings,
.pUpdateDisplayDevices = X11DRV_UpdateDisplayDevices,
.pCreateDesktopWindow = X11DRV_CreateDesktopWindow,
......
......@@ -214,8 +214,6 @@ extern BOOL X11DRV_SetCursorPos( INT x, INT y ) DECLSPEC_HIDDEN;
extern BOOL X11DRV_GetCursorPos( LPPOINT pos ) DECLSPEC_HIDDEN;
extern BOOL X11DRV_ClipCursor( LPCRECT clip ) DECLSPEC_HIDDEN;
extern LONG X11DRV_ChangeDisplaySettings( LPDEVMODEW displays, HWND hwnd, DWORD flags, LPVOID lpvoid ) DECLSPEC_HIDDEN;
extern BOOL X11DRV_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmode,
DWORD flags ) DECLSPEC_HIDDEN;
extern BOOL X11DRV_GetCurrentDisplaySettings( LPCWSTR name, LPDEVMODEW devmode ) DECLSPEC_HIDDEN;
extern BOOL X11DRV_UpdateDisplayDevices( const struct gdi_device_manager *device_manager,
BOOL force, void *param ) DECLSPEC_HIDDEN;
......
......@@ -298,7 +298,6 @@ struct user_driver_funcs
void (*pUpdateClipboard)(void);
/* display modes */
LONG (*pChangeDisplaySettings)(LPDEVMODEW,HWND,DWORD,LPVOID);
BOOL (*pEnumDisplaySettingsEx)(LPCWSTR,DWORD,LPDEVMODEW,DWORD);
BOOL (*pGetCurrentDisplaySettings)(LPCWSTR,LPDEVMODEW);
BOOL (*pUpdateDisplayDevices)(const struct gdi_device_manager *,BOOL,void*);
/* windowing functions */
......
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