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 --- dlls/winemac.drv/display.c | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index a54e78c22376..44daf4f6a51b 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -579,6 +579,13 @@ static CFDictionaryRef create_mode_dict(CGDisplayModeRef display_mode, BOOL is_o #endif
+static BOOL display_mode_is_supported(CGDisplayModeRef display_mode) +{ + uint32_t io_flags = CGDisplayModeGetIOFlags(display_mode); + return (io_flags & kDisplayModeValidFlag) && (io_flags & kDisplayModeSafeFlag); +} + + /*********************************************************************** * copy_display_modes * @@ -590,8 +597,11 @@ static CFDictionaryRef create_mode_dict(CGDisplayModeRef display_mode, BOOL is_o * returned from CGDisplayCopyAllDisplayModes() without special options. * This is especially bad if that's the user's default mode, since then * 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;
@@ -621,6 +631,7 @@ static CFArrayRef copy_display_modes(CGDirectDisplayID display) for (i = 0; i < count; i++) { CFStringRef pixel_encoding; + BOOL old_is_supported, new_is_supported; size_t width_points, height_points; size_t old_width_pixels, old_height_pixels, new_width_pixels, new_height_pixels; BOOL old_size_same, new_size_same; @@ -633,6 +644,11 @@ static CFArrayRef copy_display_modes(CGDirectDisplayID display) if (new_is_original) goto better;
+ /* Skip unsupported modes unless told to do otherwise. */ + new_is_supported = display_mode_is_supported(new_mode); + if (!new_is_supported && !include_unsupported) + goto next; + pixel_encoding = CGDisplayModeCopyPixelEncoding(new_mode); if (pixel_encoding) { @@ -659,6 +675,11 @@ static CFArrayRef copy_display_modes(CGDirectDisplayID display) if (old_is_original) goto next;
+ /* Prefer supported modes over similar unsupported ones. */ + old_is_supported = display_mode_is_supported(old_mode); + if (old_is_supported && !new_is_supported) + goto next; + /* Otherwise, prefer a mode whose pixel size equals its point size over one which is scaled. */ width_points = CGDisplayModeGetWidth(new_mode); @@ -764,7 +785,7 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode, int num_displays; CFArrayRef display_modes; struct display_mode_descriptor* desc; - CFIndex count, i, safe, best; + CFIndex count, i, best; CGDisplayModeRef best_display_mode; uint32_t best_io_flags; BOOL best_is_original; @@ -799,7 +820,7 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode, if (macdrv_get_displays(&displays, &num_displays)) return DISP_CHANGE_FAILED;
- display_modes = copy_display_modes(displays[0].displayID); + display_modes = copy_display_modes(displays[0].displayID, FALSE); if (!display_modes) { macdrv_free_displays(displays); @@ -823,7 +844,6 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode,
desc = create_original_display_mode_descriptor(displays[0].displayID);
- safe = -1; best_display_mode = NULL; count = CFArrayGetCount(display_modes); for (i = 0; i < count; i++) @@ -841,11 +861,6 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode, height *= 2; }
- if (!(io_flags & kDisplayModeValidFlag) || !(io_flags & kDisplayModeSafeFlag)) - continue; - - safe++; - if (bpp != mode_bpp) continue;
@@ -899,7 +914,7 @@ LONG CDECL macdrv_ChangeDisplaySettingsEx(LPCWSTR devname, LPDEVMODEW devmode,
better: best_display_mode = display_mode; - best = safe; + best = i; best_io_flags = io_flags; best_is_original = is_original; } @@ -1011,7 +1026,7 @@ BOOL CDECL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode, if (mode == 0 || !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;
if (modes) @@ -1040,11 +1055,6 @@ BOOL CDECL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode, { CGDisplayModeRef candidate = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
- io_flags = CGDisplayModeGetIOFlags(candidate); - if (!(flags & EDS_RAWMODE) && - (!(io_flags & kDisplayModeValidFlag) || !(io_flags & kDisplayModeSafeFlag))) - continue; - seen_modes++; if (seen_modes > mode) {