summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkemi <der.richter@gmx.de>2017-01-28 16:29:22 +0100
committerAkemi <der.richter@gmx.de>2017-02-02 16:22:27 +0100
commit6da224b1ddc6f28fe38900b6146f739d3acfb648 (patch)
treeb863684f6076b5be50b30c4e1b22249c2a5e1417
parentf39a1cb1b0214ee3fb0640e11c1eeea6b3af47eb (diff)
downloadmpv-6da224b1ddc6f28fe38900b6146f739d3acfb648.tar.bz2
mpv-6da224b1ddc6f28fe38900b6146f739d3acfb648.tar.xz
cocoa: optimise screen event handling
this optimises two things and fix a minor bug. 1. we always updated the display refresh rate on any mode change whether it was the current screen or not. now we only update the refresh rate when the mode changed happened on the current screen. 2. the windowDidChangeScreen event doesn't exclusively trigger on screen changes so we updated the display refresh rate in cases where it wasn't needed at all. since we manually keep track of the current screen, we can easily test if the screen really changed. 3. weirdly on initWithContentRect accessing the screen of the window always returned the main screen instead of the screen the window is created on. since we already use the window init method with the screen as argument, overwrite that method instead and use the screen argument.
-rw-r--r--video/out/cocoa/window.m14
-rw-r--r--video/out/cocoa_common.m15
2 files changed, 20 insertions, 9 deletions
diff --git a/video/out/cocoa/window.m b/video/out/cocoa/window.m
index aae6582dde..1ff57acde9 100644
--- a/video/out/cocoa/window.m
+++ b/video/out/cocoa/window.m
@@ -49,20 +49,22 @@
styleMask:(NSUInteger)style_mask
backing:(NSBackingStoreType)buffering_type
defer:(BOOL)flag
+ screen:(NSScreen *)screen
{
if (self = [super initWithContentRect:content_rect
styleMask:style_mask
backing:buffering_type
- defer:flag]) {
+ defer:flag
+ screen:screen]) {
[self setBackgroundColor:[NSColor blackColor]];
[self setMinSize:NSMakeSize(50,50)];
[self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
- self.targetScreen = [self screen];
- self.currentScreen = [self screen];
+ self.targetScreen = screen;
+ self.currentScreen = screen;
_is_animating = 0;
_unfs_content_frame = [self convertRectToScreen:[[self contentView] frame]];
- _unfs_screen_frame = [[self screen] frame];
+ _unfs_screen_frame = [screen frame];
}
return self;
}
@@ -171,8 +173,10 @@
if (!_is_animating && ![[self currentScreen] isEqual:[self screen]]) {
self.previousScreen = [self screen];
}
+ if (![[self currentScreen] isEqual:[self screen]]) {
+ [self.adapter windowDidChangeScreen:notification];
+ }
self.currentScreen = [self screen];
- [self.adapter windowDidChangeScreen:notification];
}
- (void)windowDidChangeScreenProfile:(NSNotification *)notification
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 5dda9c578c..6eb3dac6a9 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -433,8 +433,6 @@ static void vo_cocoa_update_displaylink(struct vo *vo)
vo_cocoa_uninit_displaylink(s);
vo_cocoa_init_displaylink(vo);
-
- flag_events(vo, VO_EVENT_WIN_STATE);
}
static double vo_cocoa_update_screen_fps(struct vo *vo)
@@ -618,8 +616,16 @@ static void cocoa_screen_reconfiguration_observer(
{
if (flags & kCGDisplaySetModeFlag) {
struct vo *vo = ctx;
- MP_WARN(vo, "detected display mode change, updating screen info\n");
- vo_cocoa_update_displaylink(vo);
+ struct vo_cocoa_state *s = vo->cocoa;
+
+ NSDictionary* sinfo = [s->current_screen deviceDescription];
+ NSNumber* sid = [sinfo objectForKey:@"NSScreenNumber"];
+ CGDirectDisplayID did = [sid longValue];
+
+ if (did == display) {
+ MP_VERBOSE(vo, "detected display mode change, updating screen refresh rate\n");
+ flag_events(vo, VO_EVENT_WIN_STATE);
+ }
}
}
@@ -972,6 +978,7 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg)
{
vo_cocoa_update_screen_info(self.vout);
vo_cocoa_update_displaylink(self.vout);
+ flag_events(self.vout, VO_EVENT_WIN_STATE);
}
- (void)windowDidEnterFullScreen:(NSNotification *)notification