Mac driver version of a8b4cf7f2d3d1fbd79308a106a84e753cdac69e8.
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 --- dlls/winemac.drv/display.c | 53 +++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index 180c0e17938c..9e0ac3182501 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -579,6 +579,48 @@ static CFDictionaryRef create_mode_dict(CGDisplayModeRef display_mode, BOOL is_o #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; +} + + static BOOL display_mode_is_supported(CGDisplayModeRef display_mode) { uint32_t io_flags = CGDisplayModeGetIOFlags(display_mode); @@ -723,7 +765,16 @@ next: #endif 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; }