summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
Diffstat (limited to 'libvo')
-rw-r--r--libvo/cocoa_common.m49
-rw-r--r--libvo/osx_common.c30
-rw-r--r--libvo/osx_common.h1
3 files changed, 63 insertions, 17 deletions
diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m
index ac66f330dc..84db6995ed 100644
--- a/libvo/cocoa_common.m
+++ b/libvo/cocoa_common.m
@@ -20,7 +20,7 @@
#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <QuartzCore/QuartzCore.h>
-#import <CoreServices/CoreServices.h> // for CGDisplayHideCursor and Gestalt
+#import <CoreServices/CoreServices.h> // for CGDisplayHideCursor
#include <dlfcn.h>
#include "cocoa_common.h"
@@ -54,6 +54,14 @@
#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask)
#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask)
+// add methods not available on OSX versions prior to 10.7
+#ifndef MAC_OS_X_VERSION_10_7
+@interface NSView (IntroducedInLion)
+- (NSRect)convertRectToBacking:(NSRect)aRect;
+- (void)setWantsBestResolutionOpenGLSurface:(BOOL)aBool;
+@end
+#endif
+
@interface GLMPlayerWindow : NSWindow <NSWindowDelegate>
- (BOOL) canBecomeKeyWindow;
- (BOOL) canBecomeMainWindow;
@@ -111,8 +119,6 @@ void resize_window(struct vo *vo);
void vo_cocoa_display_cursor(int requested_state);
void create_menu(void);
-bool is_lion_or_better(void);
-
struct vo_cocoa_state *vo_cocoa_init_state(void)
{
struct vo_cocoa_state *s = talloc_ptrtype(NULL, s);
@@ -130,6 +136,13 @@ struct vo_cocoa_state *vo_cocoa_init_state(void)
return s;
}
+static bool supports_hidpi(NSView *view)
+{
+ SEL hdpi_selector = @selector(setWantsBestResolutionOpenGLSurface:);
+ return is_osx_version_at_least(10, 7, 0) && view &&
+ [view respondsToSelector:hdpi_selector];
+}
+
bool vo_cocoa_gui_running(void)
{
return !!s;
@@ -207,8 +220,17 @@ int vo_cocoa_change_attributes(struct vo *vo)
void resize_window(struct vo *vo)
{
- vo->dwidth = [[s->window contentView] frame].size.width;
- vo->dheight = [[s->window contentView] frame].size.height;
+ NSView *view = [s->window contentView];
+ NSRect frame;
+
+ if (supports_hidpi(view)) {
+ frame = [view convertRectToBacking: [view frame]];
+ } else {
+ frame = [view frame];
+ }
+
+ vo->dwidth = frame.size.width;
+ vo->dheight = frame.size.height;
[s->glContext update];
}
@@ -247,9 +269,13 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width,
GLMPlayerOpenGLView *glView = [[GLMPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
+ // check for HiDPI support and enable it (available on 10.7 +)
+ if (supports_hidpi(glView))
+ [glView setWantsBestResolutionOpenGLSurface:YES];
+
int i = 0;
NSOpenGLPixelFormatAttribute attr[32];
- if (is_lion_or_better()) {
+ if (is_osx_version_at_least(10, 7, 0)) {
attr[i++] = NSOpenGLPFAOpenGLProfile;
attr[i++] = (gl3profile ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy);
} else if(gl3profile) {
@@ -472,17 +498,6 @@ void create_menu()
[pool release];
}
-bool is_lion_or_better(void)
-{
- SInt32 major, minor;
- Gestalt(gestaltSystemVersionMajor, &major);
- Gestalt(gestaltSystemVersionMinor, &minor);
- if(major >= 10 && minor >= 7)
- return YES;
- else
- return NO;
-}
-
@implementation GLMPlayerWindow
- (void) windowDidResize:(NSNotification *) notification
diff --git a/libvo/osx_common.c b/libvo/osx_common.c
index 428a492b7f..2aa0a28126 100644
--- a/libvo/osx_common.c
+++ b/libvo/osx_common.c
@@ -19,11 +19,13 @@
// only to get keycode definitions from HIToolbox/Events.h
#include <Carbon/Carbon.h>
+#include <CoreServices/CoreServices.h>
#include "config.h"
#include "osx_common.h"
#include "video_out.h"
#include "input/keycodes.h"
#include "input/input.h"
+#include "mp_msg.h"
/*
* Define keycodes only found in OSX >= 10.5 for older versions
@@ -113,3 +115,31 @@ int convert_key(unsigned key, unsigned charcode)
return mpkey;
return charcode;
}
+
+/**
+ * Checks at runtime that OSX version is the same or newer than the one
+ * provided as input.
+ */
+int is_osx_version_at_least(int majorv, int minorv, int bugfixv)
+{
+ OSErr err;
+ SInt32 major, minor, bugfix;
+ if ((err = Gestalt(gestaltSystemVersionMajor, &major)) != noErr)
+ goto fail;
+ if ((err = Gestalt(gestaltSystemVersionMinor, &minor)) != noErr)
+ goto fail;
+ if ((err = Gestalt(gestaltSystemVersionBugFix, &bugfix)) != noErr)
+ goto fail;
+
+ if(major > majorv ||
+ (major == majorv && (minor > minorv ||
+ (minor == minorv && bugfix >= bugfixv))))
+ return 1;
+ else
+ return 0;
+fail:
+ // There's no reason the Gestalt system call should fail on OSX.
+ mp_msg(MSGT_VO, MSGL_FATAL, "[osx] Failed to get system version number. "
+ "Please contact the developers. Error code: %ld\n", (long)err);
+ return 0;
+}
diff --git a/libvo/osx_common.h b/libvo/osx_common.h
index c5e127345f..ae31a6353d 100644
--- a/libvo/osx_common.h
+++ b/libvo/osx_common.h
@@ -22,5 +22,6 @@
struct vo;
int convert_key(unsigned key, unsigned charcode);
+int is_osx_version_at_least(int majorv, int minorv, int bugfixv);
#endif /* MPLAYER_OSX_COMMON_H */