diff options
Diffstat (limited to 'libvo/cocoa_common.m')
-rw-r--r-- | libvo/cocoa_common.m | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m index c3578d27c1..9a822cc4ea 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 +#import <CoreServices/CoreServices.h> // for CGDisplayHideCursor and Gestalt #include <dlfcn.h> #include "cocoa_common.h" @@ -37,6 +37,18 @@ #include "osx_common.h" #include "mp_msg.h" +#ifndef NSOpenGLPFAOpenGLProfile +#define NSOpenGLPFAOpenGLProfile 99 +#endif + +#ifndef NSOpenGLProfileVersionLegacy +#define NSOpenGLProfileVersionLegacy 0x1000 +#endif + +#ifndef NSOpenGLProfileVersion3_2Core +#define NSOpenGLProfileVersion3_2Core 0x3200 +#endif + #define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask) #define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask) @@ -97,6 +109,8 @@ 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); @@ -216,7 +230,8 @@ void vo_cocoa_ontop(struct vo *vo) } int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, - uint32_t d_height, uint32_t flags) + uint32_t d_height, uint32_t flags, + int gl3profile) { struct MPOpts *opts = vo->opts; if (s->current_video_size.width > 0 || s->current_video_size.height > 0) @@ -230,13 +245,27 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width, GLMPlayerOpenGLView *glView = [[GLMPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; - NSOpenGLPixelFormatAttribute attrs[] = { - NSOpenGLPFADoubleBuffer, // double buffered - NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer - (NSOpenGLPixelFormatAttribute)0 - }; - - s->pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease]; + int i = 0; + NSOpenGLPixelFormatAttribute attr[32]; + if (is_lion_or_better()) { + attr[i++] = NSOpenGLPFAOpenGLProfile; + attr[i++] = (gl3profile ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy); + } else if(gl3profile) { + mp_msg(MSGT_VO, MSGL_ERR, + "[cocoa] Invalid pixel format attribute " + "(GL3 is not supported on OSX versions prior to 10.7)\n"); + return -1; + } + attr[i++] = NSOpenGLPFADoubleBuffer; // double buffered + attr[i] = (NSOpenGLPixelFormatAttribute)0; + + s->pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attr] autorelease]; + if (!s->pixelFormat) { + mp_msg(MSGT_VO, MSGL_ERR, + "[cocoa] Invalid pixel format attribute " + "(GL3 not supported?)\n"); + return -1; + } s->glContext = [[NSOpenGLContext alloc] initWithFormat:s->pixelFormat shareContext:nil]; create_menu(); @@ -376,7 +405,23 @@ void *vo_cocoa_cgl_context(void) void *vo_cocoa_cgl_pixel_format(void) { - return [s->pixelFormat CGLPixelFormatObj]; + return CGLGetPixelFormat(vo_cocoa_cgl_context()); +} + +int vo_cocoa_cgl_color_size(void) +{ + GLint value; + CGLDescribePixelFormat(vo_cocoa_cgl_pixel_format(), 0, + kCGLPFAColorSize, &value); + switch (value) { + case 32: + case 24: + return 8; + case 16: + return 5; + } + + return 8; } void create_menu() @@ -402,6 +447,17 @@ void create_menu() [menuItem 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 |