summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2015-02-03 21:43:20 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2015-02-03 22:07:37 +0100
commitaeb1fca0d4c8c67dbd8a550a7f16144738597868 (patch)
tree301d98bd1cee1ca9163da16b7fe5a9fa295f61f0 /video/out
parenta33b46194c3525cb585cc78b449ec275dbfd7f83 (diff)
downloadmpv-aeb1fca0d4c8c67dbd8a550a7f16144738597868.tar.bz2
mpv-aeb1fca0d4c8c67dbd8a550a7f16144738597868.tar.xz
cocoa: automatically fetch display-fps from the monitor
Comment explains why I have been so doubtful at adding this. The Apple docs say CGDisplayModeGetRefreshRate is supposed to work only for CRTs, but it doesn't, and actually works for LCD TVs connected over HDMI and external displays (at least that's what I'm told, I don't have the hardware to test). Maybe Apple docs are incorrect. Since AFAIK Apple doesn't want to give us a better API – maybe in the fear we might be able to actually write some useful software instead of "apps" – I decided not to care as well and commit this.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/cocoa_common.m26
1 files changed, 26 insertions, 0 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index e89504c472..306b5aedd2 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -62,6 +62,7 @@ struct vo_cocoa_state {
NSScreen *current_screen;
NSScreen *fs_screen;
+ double screen_fps;
NSInteger window_level;
@@ -256,6 +257,27 @@ static void vo_cocoa_update_screens_pointers(struct vo *vo)
get_screen_handle(vo, opts->fsscreen_id, s->window, &s->fs_screen);
}
+static void vo_cocoa_update_screen_fps(struct vo *vo)
+{
+ struct vo_cocoa_state *s = vo->cocoa;
+ NSScreen *screen = vo->opts->fullscreen ? s->fs_screen : s->current_screen;
+ NSDictionary* sinfo = [screen deviceDescription];
+ NSNumber* sid = [sinfo objectForKey:@"NSScreenNumber"];
+ CGDirectDisplayID did = [sid longValue];
+ 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;
+ }
+}
+
static void vo_cocoa_update_screen_info(struct vo *vo, struct mp_rect *out_rc)
{
struct vo_cocoa_state *s = vo->cocoa;
@@ -264,6 +286,7 @@ static void vo_cocoa_update_screen_info(struct vo *vo, struct mp_rect *out_rc)
return;
vo_cocoa_update_screens_pointers(vo);
+ vo_cocoa_update_screen_fps(vo);
if (out_rc) {
NSRect r = [s->current_screen frame];
@@ -649,6 +672,9 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
case VOCTRL_GET_ICC_PROFILE:
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;
}
return VO_NOTIMPL;
}