diff --git a/panda/src/cocoadisplay/cocoaGraphicsPipe.mm b/panda/src/cocoadisplay/cocoaGraphicsPipe.mm index abadedc7e6..fb83d75718 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsPipe.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsPipe.mm @@ -21,7 +21,9 @@ #import #import +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 #import +#endif #include @@ -32,7 +34,9 @@ static void init_app() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [NSApplication sharedApplication]; +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; +#endif [NSApp finishLaunching]; [NSApp activateIgnoringOtherApps:YES]; @@ -143,7 +147,7 @@ load_display_information() { //_display_information->_device_id = CGDisplaySerialNumber(_display); // Display modes -#if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 CFArrayRef modes = CGDisplayCopyAllDisplayModes(_display, NULL); size_t num_modes = CFArrayGetCount(modes); _display_information->_total_display_modes = num_modes; diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.h b/panda/src/cocoadisplay/cocoaGraphicsWindow.h index 4eedac3a7a..1a59265ae4 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.h +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.h @@ -66,8 +66,13 @@ protected: virtual void close_window(); virtual bool open_window(); +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 CGDisplayModeRef find_display_mode(int width, int height); bool do_switch_fullscreen(CGDisplayModeRef mode); +#else + CFDictionaryRef find_display_mode(int width, int height); + bool do_switch_fullscreen(CFDictionaryRef mode); +#endif virtual void mouse_mode_absolute(); virtual void mouse_mode_relative(); @@ -82,11 +87,17 @@ private: NSView *_view; NSUInteger _modifier_keys; CGDirectDisplayID _display; - CGDisplayModeRef _fullscreen_mode; - CGDisplayModeRef _windowed_mode; bool _mouse_hidden; bool _context_needs_update; +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + CGDisplayModeRef _fullscreen_mode; + CGDisplayModeRef _windowed_mode; +#else + CFDictionaryRef _fullscreen_mode; + CFDictionaryRef _windowed_mode; +#endif + typedef pmap IconImages; IconImages _images; diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 8ea9acd065..f061b486b0 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -565,8 +565,14 @@ open_window() { if (_properties.get_fullscreen()) { // Change the display mode. - CGDisplayModeRef mode = find_display_mode(_properties.get_x_size(), - _properties.get_y_size()); +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + CGDisplayModeRef mode; +#else + CFDictionaryRef mode; +#endif + + mode = find_display_mode(_properties.get_x_size(), + _properties.get_y_size()); if (mode == NULL) { cocoadisplay_cat.error() @@ -725,7 +731,13 @@ set_properties_now(WindowProperties &properties) { height = _properties.get_y_size(); } - CGDisplayModeRef mode = find_display_mode(width, height); +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + CGDisplayModeRef mode; +#else + CFDictionaryRef mode; +#endif + + mode = find_display_mode(width, height); if (mode == NULL) { cocoadisplay_cat.error() @@ -796,7 +808,11 @@ set_properties_now(WindowProperties &properties) { properties.clear_size(); } else { +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 CGDisplayModeRef mode = find_display_mode(width, height); +#else + CFDictionaryRef mode = find_display_mode(width, height); +#endif if (mode == NULL) { cocoadisplay_cat.error() @@ -1010,6 +1026,7 @@ set_properties_now(WindowProperties &properties) { // Description: Returns an appropriate CGDisplayModeRef for the // given width and height, or NULL if none was found. //////////////////////////////////////////////////////////////////// +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 CGDisplayModeRef CocoaGraphicsWindow:: find_display_mode(int width, int height) { CFArrayRef modes = CGDisplayCopyAllDisplayModes(_display, NULL); @@ -1053,6 +1070,60 @@ find_display_mode(int width, int height) { CFRelease(modes); return NULL; } +#else // Version for pre-10.6. +CFDictionaryRef CocoaGraphicsWindow:: +find_display_mode(int width, int height) { + // Get the current mode and extract its properties. + CFDictionaryRef current_mode = CGDisplayCurrentMode(_display); + int current_width, current_height, current_bpp, current_refresh_rate; + + CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(current_mode, kCGDisplayWidth), + kCFNumberIntType, ¤t_width); + + CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(current_mode, kCGDisplayHeight), + kCFNumberIntType, ¤t_height); + + CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(current_mode, kCGDisplayBitsPerPixel), + kCFNumberIntType, ¤t_bpp); + + CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(current_mode, kCGDisplayRefreshRate), + kCFNumberIntType, ¤t_refresh_rate); + + // Check if it is suitable and if so, return it. + if (current_width == width && current_height == height) { + return current_mode; + } + + // Iterate over the modes to find a suitable one. + CFArrayRef modes = CGDisplayAvailableModes(_display); + size_t num_modes = CFArrayGetCount(modes); + int mode_width, mode_height, mode_bpp, mode_refresh_rate; + + for (size_t i = 0; i < num_modes; ++i) { + CFDictionaryRef mode = (CFDictionaryRef) CFArrayGetValueAtIndex(modes, i); + + CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayWidth), + kCFNumberIntType, &mode_width); + + CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayHeight), + kCFNumberIntType, &mode_height); + + CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayBitsPerPixel), + kCFNumberIntType, &mode_bpp); + + CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(mode, kCGDisplayRefreshRate), + kCFNumberIntType, &mode_refresh_rate); + + if (mode_width == width && mode_height == height && + mode_refresh_rate == current_refresh_rate && + mode_bpp == current_bpp) { + return mode; + } + } + + return NULL; +} +#endif //////////////////////////////////////////////////////////////////// // Function: CocoaGraphicsWindow::do_switch_fullscreen @@ -1061,8 +1132,13 @@ find_display_mode(int width, int height) { // back to windowed if NULL was given. Returns true // on success, false on failure. //////////////////////////////////////////////////////////////////// +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 bool CocoaGraphicsWindow:: do_switch_fullscreen(CGDisplayModeRef mode) { +#else +bool CocoaGraphicsWindow:: +do_switch_fullscreen(CFDictionaryRef mode) { +#endif if (mode == NULL) { if (_windowed_mode == NULL) { // Already windowed. @@ -1070,8 +1146,12 @@ do_switch_fullscreen(CGDisplayModeRef mode) { } // Switch back to the mode we were in when we were still windowed. +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 CGDisplaySetDisplayMode(_display, _windowed_mode, NULL); CGDisplayModeRelease(_windowed_mode); +#else + CGDisplaySwitchToMode(_display, _windowed_mode); +#endif CGDisplayRelease(_display); _windowed_mode = NULL; _context_needs_update = true; @@ -1081,15 +1161,28 @@ do_switch_fullscreen(CGDisplayModeRef mode) { // Already fullscreen in that size. return true; } + + // Store the existing mode under _windowed_mode. +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 _windowed_mode = CGDisplayCopyDisplayMode(_display); +#else + _windowed_mode = CGDisplayCurrentMode(_display); +#endif _fullscreen_mode = mode; _context_needs_update = true; - if (CGDisplaySetDisplayMode(_display, _fullscreen_mode, NULL) != kCGErrorSuccess) { + CGError err; +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + err = CGDisplaySetDisplayMode(_display, _fullscreen_mode, NULL); +#else + err = CGDisplaySwitchToMode(_display, _fullscreen_mode); +#endif + + if (err != kCGErrorSuccess) { return false; } - CGDisplayCaptureWithOptions(_display, kCGCaptureNoFill); + CGDisplayCapture(_display); NSRect frame = [[[_view window] screen] frame]; if (cocoadisplay_cat.is_debug()) { diff --git a/panda/src/cocoadisplay/cocoaPandaView.mm b/panda/src/cocoadisplay/cocoaPandaView.mm index fc31079ff7..05c73213e5 100644 --- a/panda/src/cocoadisplay/cocoaPandaView.mm +++ b/panda/src/cocoadisplay/cocoaPandaView.mm @@ -22,7 +22,9 @@ self = [super initWithFrame: frameRect]; _context = context; +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 [self setCanDrawConcurrently:YES]; +#endif cocoadisplay_cat.debug() << "Created CocoaPandaView " << self << " for GraphicsWindow " << window << "\n"; diff --git a/panda/src/cocoadisplay/cocoaPandaWindow.mm b/panda/src/cocoadisplay/cocoaPandaWindow.mm index 9f2a737276..411f08a25c 100644 --- a/panda/src/cocoadisplay/cocoaPandaWindow.mm +++ b/panda/src/cocoadisplay/cocoaPandaWindow.mm @@ -29,7 +29,9 @@ [self setDelegate:delegate]; [self setOpaque:YES]; [self setReleasedWhenClosed:YES]; +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 [self setAllowsConcurrentViewDrawing:YES]; +#endif // Necessary to be able to accept mouseMoved in the NSView [self setAcceptsMouseMovedEvents:YES];