winemac.drv: Sort display modes.

Mac driver version of a8b4cf7f2d.

Combined with the previous patch that reordered synthesized modes,
the Mac driver implementation of EnumDisplayModesEx now returns modes
in the same order as the X11 driver.

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:
Tim Clem 2022-03-22 11:06:02 -07:00 committed by Alexandre Julliard
parent c2936f70e3
commit e66c9cadbb
1 changed files with 52 additions and 1 deletions

View File

@ -656,6 +656,48 @@ static BOOL mode_is_preferred(CGDisplayModeRef new_mode, CGDisplayModeRef old_mo
#endif #endif
static CFComparisonResult mode_compare(const void *p1, const void *p2, void *context)
{
CGDisplayModeRef a = (CGDisplayModeRef)p1, b = (CGDisplayModeRef)p2;
size_t a_val, b_val;
double a_refresh_rate, b_refresh_rate;
/* Sort by bpp descending, */
a_val = display_mode_bits_per_pixel(a);
b_val = display_mode_bits_per_pixel(b);
if (a_val < b_val)
return kCFCompareGreaterThan;
else if (a_val > b_val)
return kCFCompareLessThan;
/* then width ascending, */
a_val = CGDisplayModeGetWidth(a);
b_val = CGDisplayModeGetWidth(b);
if (a_val < b_val)
return kCFCompareLessThan;
else if (a_val > b_val)
return kCFCompareGreaterThan;
/* then height ascending, */
a_val = CGDisplayModeGetHeight(a);
b_val = CGDisplayModeGetHeight(b);
if (a_val < b_val)
return kCFCompareLessThan;
else if (a_val > b_val)
return kCFCompareGreaterThan;
/* then refresh rate descending. */
a_refresh_rate = CGDisplayModeGetRefreshRate(a);
b_refresh_rate = CGDisplayModeGetRefreshRate(b);
if (a_refresh_rate < b_refresh_rate)
return kCFCompareGreaterThan;
else if (a_refresh_rate > b_refresh_rate)
return kCFCompareLessThan;
return kCFCompareEqualTo;
}
/*********************************************************************** /***********************************************************************
* copy_display_modes * copy_display_modes
* *
@ -725,7 +767,16 @@ static CFArrayRef copy_display_modes(CGDirectDisplayID display, BOOL include_uns
#endif #endif
modes = CGDisplayCopyAllDisplayModes(display, NULL); modes = CGDisplayCopyAllDisplayModes(display, NULL);
return modes; if (modes)
{
CFIndex count = CFArrayGetCount(modes);
CFMutableArrayRef sorted_modes = CFArrayCreateMutableCopy(NULL, count, modes);
CFRelease(modes);
CFArraySortValues(sorted_modes, CFRangeMake(0, count), mode_compare, NULL);
return sorted_modes;
}
return NULL;
} }