[gtk/wip/chergert/quartz4u] macos: calculate refresh rate for monitors with fallback



commit ccba9dd1555768073e748fc97c4f84e2d564dcc1
Author: Christian Hergert <chergert redhat com>
Date:   Thu May 14 15:13:12 2020 -0700

    macos: calculate refresh rate for monitors with fallback

 gdk/macos/gdkmacosdisplay-private.h |  1 +
 gdk/macos/gdkmacosdisplay.c         | 14 +++++++++++++-
 gdk/macos/gdkmacosmonitor.c         | 11 ++++++++---
 3 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/gdk/macos/gdkmacosdisplay-private.h b/gdk/macos/gdkmacosdisplay-private.h
index b94d0e4021..07f6921f99 100644
--- a/gdk/macos/gdkmacosdisplay-private.h
+++ b/gdk/macos/gdkmacosdisplay-private.h
@@ -133,6 +133,7 @@ void             _gdk_macos_display_surface_became_key             (GdkMacosDisp
                                                                     GdkMacosSurface *surface);
 void             _gdk_macos_display_surface_raised                 (GdkMacosDisplay *self,
                                                                     GdkMacosSurface *surface);
+int              _gdk_macos_display_get_nominal_refresh_rate       (GdkMacosDisplay *self);
 
 G_END_DECLS
 
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 18fa02c582..12bbb01442 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -725,8 +725,9 @@ _gdk_macos_display_open (const gchar *display_name)
   self->keymap = _gdk_macos_keymap_new (self);
 
   gdk_macos_display_load_seat (self);
-  _gdk_macos_display_reload_monitors (self);
+  /* Load CVDisplayLink before monitors to access refresh rates */
   gdk_macos_display_load_display_link (self);
+  _gdk_macos_display_reload_monitors (self);
 
   CFNotificationCenterAddObserver (CFNotificationCenterGetDistributedCenter (),
                                    self,
@@ -966,3 +967,14 @@ _gdk_macos_display_surface_raised (GdkMacosDisplay *self,
 
   g_queue_push_head_link (&self->sorted_surfaces, &surface->sorted);
 }
+
+int
+_gdk_macos_display_get_nominal_refresh_rate (GdkMacosDisplay *self)
+{
+  g_return_val_if_fail (GDK_IS_MACOS_DISPLAY (self), 60 * 1000);
+
+  if (self->frame_source == NULL)
+    return 60 * 1000;
+
+  return ((GdkDisplayLinkSource *)self->frame_source)->refresh_rate;
+}
diff --git a/gdk/macos/gdkmacosmonitor.c b/gdk/macos/gdkmacosmonitor.c
index 4bb3c195c2..8cb9ce7d5c 100644
--- a/gdk/macos/gdkmacosmonitor.c
+++ b/gdk/macos/gdkmacosmonitor.c
@@ -208,7 +208,6 @@ _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self)
   main_bounds = CGDisplayBounds (CGMainDisplayID ());
   width = CGDisplayModeGetWidth (mode);
   pixel_width = CGDisplayModeGetPixelWidth (mode);
-  refresh_rate = CGDisplayModeGetRefreshRate (mode);
   has_opengl = CGDisplayUsesOpenGLAcceleration (self->screen_id);
   subpixel_layout = GetSubpixelLayout (self->screen_id);
   name = GetLocalizedName (self->screen_id);
@@ -220,8 +219,6 @@ _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self)
   width_mm = size.width;
   height_mm = size.height;
 
-  CGDisplayModeRelease (mode);
-
   /* This requires that the display bounds have been
    * updated before the monitor is reconfigured.
    */
@@ -233,6 +230,13 @@ _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self)
   geom.width = bounds.size.width;
   geom.height = bounds.size.height;
 
+  /* We will often get 0 back from CGDisplayModeGetRefreshRate().  We
+   * can fallback by getting it from CoreVideo based on a CVDisplayLink
+   * setting (which is also used by the frame clock).
+   */
+  if (!(refresh_rate = CGDisplayModeGetRefreshRate (mode)))
+    refresh_rate = _gdk_macos_display_get_nominal_refresh_rate (display);
+
   gdk_monitor_set_connector (GDK_MONITOR (self), connector);
   gdk_monitor_set_model (GDK_MONITOR (self), name);
   gdk_monitor_set_position (GDK_MONITOR (self), geom.x, geom.y);
@@ -250,6 +254,7 @@ _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self)
    */
   self->has_opengl = !!has_opengl;
 
+  CGDisplayModeRelease (mode);
   g_free (name);
   g_free (connector);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]