From eacf22e42a6bbce8a32e64f5563ac431122c1186 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 3 Feb 2015 22:59:54 +0100 Subject: 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 --- video/out/cocoa_common.m | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'video/out') 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; } -- cgit v1.2.3