winemac.drv: Add a flag to filter unsupported modes in copy_display_modes.
Prefer supported display modes over similar unsupported ones. Centralizes the logic from the ChangeDisplaySettingsEx and EnumDisplaySettingsEx implementations. Signed-off-by: Tim Clem <tclem@codeweavers.com> Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
5c09278ab6
commit
8a8808e98b
|
@ -524,6 +524,13 @@ static int get_default_bpp(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static BOOL display_mode_is_supported(CGDisplayModeRef display_mode)
|
||||||
|
{
|
||||||
|
uint32_t io_flags = CGDisplayModeGetIOFlags(display_mode);
|
||||||
|
return (io_flags & kDisplayModeValidFlag) && (io_flags & kDisplayModeSafeFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
|
#if defined(MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
|
||||||
static CFDictionaryRef create_mode_dict(CGDisplayModeRef display_mode, BOOL is_original)
|
static CFDictionaryRef create_mode_dict(CGDisplayModeRef display_mode, BOOL is_original)
|
||||||
{
|
{
|
||||||
|
@ -579,8 +586,10 @@ static CFDictionaryRef create_mode_dict(CGDisplayModeRef display_mode, BOOL is_o
|
||||||
|
|
||||||
|
|
||||||
static BOOL mode_is_preferred(CGDisplayModeRef new_mode, CGDisplayModeRef old_mode,
|
static BOOL mode_is_preferred(CGDisplayModeRef new_mode, CGDisplayModeRef old_mode,
|
||||||
struct display_mode_descriptor *original_mode_desc)
|
struct display_mode_descriptor *original_mode_desc,
|
||||||
|
BOOL include_unsupported)
|
||||||
{
|
{
|
||||||
|
BOOL new_is_supported;
|
||||||
CFStringRef pixel_encoding;
|
CFStringRef pixel_encoding;
|
||||||
size_t width_points, height_points;
|
size_t width_points, height_points;
|
||||||
size_t old_width_pixels, old_height_pixels, new_width_pixels, new_height_pixels;
|
size_t old_width_pixels, old_height_pixels, new_width_pixels, new_height_pixels;
|
||||||
|
@ -591,6 +600,11 @@ static BOOL mode_is_preferred(CGDisplayModeRef new_mode, CGDisplayModeRef old_mo
|
||||||
if (display_mode_matches_descriptor(new_mode, original_mode_desc))
|
if (display_mode_matches_descriptor(new_mode, original_mode_desc))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
/* Skip unsupported modes unless told to do otherwise. */
|
||||||
|
new_is_supported = display_mode_is_supported(new_mode);
|
||||||
|
if (!new_is_supported && !include_unsupported)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
pixel_encoding = CGDisplayModeCopyPixelEncoding(new_mode);
|
pixel_encoding = CGDisplayModeCopyPixelEncoding(new_mode);
|
||||||
if (pixel_encoding)
|
if (pixel_encoding)
|
||||||
{
|
{
|
||||||
|
@ -615,6 +629,10 @@ static BOOL mode_is_preferred(CGDisplayModeRef new_mode, CGDisplayModeRef old_mo
|
||||||
if (display_mode_matches_descriptor(old_mode, original_mode_desc))
|
if (display_mode_matches_descriptor(old_mode, original_mode_desc))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
/* Prefer supported modes over similar unsupported ones. */
|
||||||
|
if (!new_is_supported && display_mode_is_supported(old_mode))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
/* Otherwise, prefer a mode whose pixel size equals its point size over one which
|
/* Otherwise, prefer a mode whose pixel size equals its point size over one which
|
||||||
is scaled. */
|
is scaled. */
|
||||||
width_points = CGDisplayModeGetWidth(new_mode);
|
width_points = CGDisplayModeGetWidth(new_mode);
|
||||||
|
@ -649,8 +667,11 @@ static BOOL mode_is_preferred(CGDisplayModeRef new_mode, CGDisplayModeRef old_mo
|
||||||
* returned from CGDisplayCopyAllDisplayModes() without special options.
|
* returned from CGDisplayCopyAllDisplayModes() without special options.
|
||||||
* This is especially bad if that's the user's default mode, since then
|
* This is especially bad if that's the user's default mode, since then
|
||||||
* no "available" mode matches the initial settings.
|
* no "available" mode matches the initial settings.
|
||||||
|
*
|
||||||
|
* If include_unsupported is FALSE, display modes with IO flags that
|
||||||
|
* indicate that they are invalid or unsafe are filtered.
|
||||||
*/
|
*/
|
||||||
static CFArrayRef copy_display_modes(CGDirectDisplayID display)
|
static CFArrayRef copy_display_modes(CGDirectDisplayID display, BOOL include_unsupported)
|
||||||
{
|
{
|
||||||
CFArrayRef modes = NULL;
|
CFArrayRef modes = NULL;
|
||||||
|
|
||||||
|
@ -684,7 +705,7 @@ static CFArrayRef copy_display_modes(CGDirectDisplayID display)
|
||||||
CFDictionaryRef key = create_mode_dict(new_mode, new_is_original);
|
CFDictionaryRef key = create_mode_dict(new_mode, new_is_original);
|
||||||
CGDisplayModeRef old_mode = (CGDisplayModeRef)CFDictionaryGetValue(modes_by_size, key);
|
CGDisplayModeRef old_mode = (CGDisplayModeRef)CFDictionaryGetValue(modes_by_size, key);
|
||||||
|
|
||||||
if (mode_is_preferred(new_mode, old_mode, desc))
|
if (mode_is_preferred(new_mode, old_mode, desc, include_unsupported))
|
||||||
CFDictionarySetValue(modes_by_size, key, new_mode);
|
CFDictionarySetValue(modes_by_size, key, new_mode);
|
||||||
|
|
||||||
CFRelease(key);
|
CFRelease(key);
|
||||||
|
@ -766,7 +787,7 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode,
|
||||||
int num_displays;
|
int num_displays;
|
||||||
CFArrayRef display_modes;
|
CFArrayRef display_modes;
|
||||||
struct display_mode_descriptor* desc;
|
struct display_mode_descriptor* desc;
|
||||||
CFIndex count, i, safe, best;
|
CFIndex count, i, best;
|
||||||
CGDisplayModeRef best_display_mode;
|
CGDisplayModeRef best_display_mode;
|
||||||
uint32_t best_io_flags;
|
uint32_t best_io_flags;
|
||||||
BOOL best_is_original;
|
BOOL best_is_original;
|
||||||
|
@ -801,7 +822,7 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode,
|
||||||
if (macdrv_get_displays(&displays, &num_displays))
|
if (macdrv_get_displays(&displays, &num_displays))
|
||||||
return DISP_CHANGE_FAILED;
|
return DISP_CHANGE_FAILED;
|
||||||
|
|
||||||
display_modes = copy_display_modes(displays[0].displayID);
|
display_modes = copy_display_modes(displays[0].displayID, FALSE);
|
||||||
if (!display_modes)
|
if (!display_modes)
|
||||||
{
|
{
|
||||||
macdrv_free_displays(displays);
|
macdrv_free_displays(displays);
|
||||||
|
@ -825,7 +846,6 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode,
|
||||||
|
|
||||||
desc = create_original_display_mode_descriptor(displays[0].displayID);
|
desc = create_original_display_mode_descriptor(displays[0].displayID);
|
||||||
|
|
||||||
safe = -1;
|
|
||||||
best_display_mode = NULL;
|
best_display_mode = NULL;
|
||||||
count = CFArrayGetCount(display_modes);
|
count = CFArrayGetCount(display_modes);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
|
@ -843,11 +863,6 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode,
|
||||||
height *= 2;
|
height *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(io_flags & kDisplayModeValidFlag) || !(io_flags & kDisplayModeSafeFlag))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
safe++;
|
|
||||||
|
|
||||||
if (bpp != mode_bpp)
|
if (bpp != mode_bpp)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -901,7 +916,7 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode,
|
||||||
|
|
||||||
better:
|
better:
|
||||||
best_display_mode = display_mode;
|
best_display_mode = display_mode;
|
||||||
best = safe;
|
best = i;
|
||||||
best_io_flags = io_flags;
|
best_io_flags = io_flags;
|
||||||
best_is_original = is_original;
|
best_is_original = is_original;
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1028,7 @@ BOOL CDECL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode,
|
||||||
if (mode == 0 || !modes)
|
if (mode == 0 || !modes)
|
||||||
{
|
{
|
||||||
if (modes) CFRelease(modes);
|
if (modes) CFRelease(modes);
|
||||||
modes = copy_display_modes(displays[0].displayID);
|
modes = copy_display_modes(displays[0].displayID, (flags & EDS_RAWMODE) != 0);
|
||||||
modes_has_8bpp = modes_has_16bpp = FALSE;
|
modes_has_8bpp = modes_has_16bpp = FALSE;
|
||||||
|
|
||||||
if (modes)
|
if (modes)
|
||||||
|
@ -1042,11 +1057,6 @@ BOOL CDECL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode,
|
||||||
{
|
{
|
||||||
CGDisplayModeRef candidate = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
|
CGDisplayModeRef candidate = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
|
||||||
|
|
||||||
io_flags = CGDisplayModeGetIOFlags(candidate);
|
|
||||||
if (!(flags & EDS_RAWMODE) &&
|
|
||||||
(!(io_flags & kDisplayModeValidFlag) || !(io_flags & kDisplayModeSafeFlag)))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
seen_modes++;
|
seen_modes++;
|
||||||
if (seen_modes > mode)
|
if (seen_modes > mode)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue