Tim Clem : winemac.drv: Sort display modes.

Alexandre Julliard julliard at winehq.org
Wed Mar 23 17:03:54 CDT 2022


Module: wine
Branch: master
Commit: e66c9cadbb2f97d79a523927516d0649c4ae09e7
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=e66c9cadbb2f97d79a523927516d0649c4ae09e7

Author: Tim Clem <tclem at codeweavers.com>
Date:   Tue Mar 22 11:06:02 2022 -0700

winemac.drv: Sort display modes.

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 at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 d43baf6bd68..023f7b80ed8 100644
--- a/dlls/winemac.drv/display.c
+++ b/dlls/winemac.drv/display.c
@@ -656,6 +656,48 @@ static BOOL mode_is_preferred(CGDisplayModeRef new_mode, CGDisplayModeRef old_mo
 #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
  *
@@ -725,7 +767,16 @@ static CFArrayRef copy_display_modes(CGDirectDisplayID display, BOOL include_uns
 #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;
 }
 
 




More information about the wine-cvs mailing list