summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2015-02-03 22:59:54 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2015-02-03 22:59:54 +0100
commiteacf22e42a6bbce8a32e64f5563ac431122c1186 (patch)
tree1a3c38b2199b8f11845de252bb4b681a99c8c6de
parentaeb1fca0d4c8c67dbd8a550a7f16144738597868 (diff)
downloadmpv-eacf22e42a6bbce8a32e64f5563ac431122c1186.tar.bz2
mpv-eacf22e42a6bbce8a32e64f5563ac431122c1186.tar.xz
cocoa: improve refresh rate fallback code
Apparently CoreGraphics reports the actual refresh rate. DisplayLink can also query the nominal refresh rate of the display so we use that as fallback instead of the fugly 60fps hardcode added in aeb1fca0d. Props to people on https://github.com/glfw/glfw/issues/137
-rw-r--r--video/out/cocoa_common.m23
1 files changed, 14 insertions, 9 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 306b5aedd2..8d1e0ef653 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -267,14 +267,17 @@ static void vo_cocoa_update_screen_fps(struct vo *vo)
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(did);
s->screen_fps = CGDisplayModeGetRefreshRate(mode);
CGDisplayModeRelease(mode);
+
if (s->screen_fps == 0.0) {
- // Most internal Apple monitors and laptop monitors report 0 instead
- // of 60fps. Assume them to be 60hz. This is technically incorrect but
- // works most of the time, and seems to be used in most open source
- // software for lack of a better Apple API.
- MP_VERBOSE(vo, "CoreGraphics reports a 0fps display. Assuming internal "
- "Apple monitor @ 60fps instead.\n");
- s->screen_fps = 60.0;
+ // Fallback to using Nominal refresh rate from DisplayLink,
+ // CVDisplayLinkGet *Actual* OutputVideoRefreshPeriod seems to
+ // return 0 as well if CG returns 0
+ CVDisplayLinkRef link;
+ CVDisplayLinkCreateWithCGDisplay(did, &link);
+ const CVTime t = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
+ if (!(t.flags & kCVTimeIsIndefinite))
+ s->screen_fps = (t.timeScale / (double) t.timeValue);
+ CVDisplayLinkRelease(link);
}
}
@@ -673,8 +676,10 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
vo_cocoa_control_get_icc_profile(vo, arg);
return VO_TRUE;
case VOCTRL_GET_DISPLAY_FPS:
- *(double *)arg = vo->cocoa->screen_fps;
- return VO_TRUE;
+ if (vo->cocoa->screen_fps > 0.0) {
+ *(double *)arg = vo->cocoa->screen_fps;
+ return VO_TRUE;
+ }
}
return VO_NOTIMPL;
}