mirror of https://github.com/mpv-player/mpv
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
This commit is contained in:
parent
aeb1fca0d4
commit
eacf22e42a
|
@ -267,14 +267,17 @@ static void vo_cocoa_update_screen_fps(struct vo *vo)
|
||||||
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(did);
|
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(did);
|
||||||
s->screen_fps = CGDisplayModeGetRefreshRate(mode);
|
s->screen_fps = CGDisplayModeGetRefreshRate(mode);
|
||||||
CGDisplayModeRelease(mode);
|
CGDisplayModeRelease(mode);
|
||||||
|
|
||||||
if (s->screen_fps == 0.0) {
|
if (s->screen_fps == 0.0) {
|
||||||
// Most internal Apple monitors and laptop monitors report 0 instead
|
// Fallback to using Nominal refresh rate from DisplayLink,
|
||||||
// of 60fps. Assume them to be 60hz. This is technically incorrect but
|
// CVDisplayLinkGet *Actual* OutputVideoRefreshPeriod seems to
|
||||||
// works most of the time, and seems to be used in most open source
|
// return 0 as well if CG returns 0
|
||||||
// software for lack of a better Apple API.
|
CVDisplayLinkRef link;
|
||||||
MP_VERBOSE(vo, "CoreGraphics reports a 0fps display. Assuming internal "
|
CVDisplayLinkCreateWithCGDisplay(did, &link);
|
||||||
"Apple monitor @ 60fps instead.\n");
|
const CVTime t = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
|
||||||
s->screen_fps = 60.0;
|
if (!(t.flags & kCVTimeIsIndefinite))
|
||||||
|
s->screen_fps = (t.timeScale / (double) t.timeValue);
|
||||||
|
CVDisplayLinkRelease(link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,9 +676,11 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
|
||||||
vo_cocoa_control_get_icc_profile(vo, arg);
|
vo_cocoa_control_get_icc_profile(vo, arg);
|
||||||
return VO_TRUE;
|
return VO_TRUE;
|
||||||
case VOCTRL_GET_DISPLAY_FPS:
|
case VOCTRL_GET_DISPLAY_FPS:
|
||||||
|
if (vo->cocoa->screen_fps > 0.0) {
|
||||||
*(double *)arg = vo->cocoa->screen_fps;
|
*(double *)arg = vo->cocoa->screen_fps;
|
||||||
return VO_TRUE;
|
return VO_TRUE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return VO_NOTIMPL;
|
return VO_NOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue