[Bf-blender-cvs] [cd1e6df5341] master: macOS/Ghost: Replace NSAutoreleasePool with @autoreleasepool
Corbin Dunn
noreply at git.blender.org
Tue Mar 9 17:11:37 CET 2021
Commit: cd1e6df534105990d726d610dca763099ccfdc1a
Author: Corbin Dunn
Date: Tue Mar 9 21:38:41 2021 +0530
Branches: master
https://developer.blender.org/rBcd1e6df534105990d726d610dca763099ccfdc1a
macOS/Ghost: Replace NSAutoreleasePool with @autoreleasepool
- Automatic and guaranteed cleanup.
- Improves readability and reduces chances of errors by removing
`[pool drain]` statements.
Reviewed By: #platform_macos, sebbas, ankitm
Differential Revision: https://developer.blender.org/D10616
===================================================================
M intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index 4a23b30e078..e7bbf3bb462 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -563,97 +563,96 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
SetFrontProcess(&psn);
}*/
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [NSApplication sharedApplication]; // initializes NSApp
-
- if ([NSApp mainMenu] == nil) {
- NSMenu *mainMenubar = [[NSMenu alloc] init];
- NSMenuItem *menuItem;
- NSMenu *windowMenu;
- NSMenu *appMenu;
-
- // Create the application menu
- appMenu = [[NSMenu alloc] initWithTitle:@"Blender"];
-
- [appMenu addItemWithTitle:@"About Blender"
- action:@selector(orderFrontStandardAboutPanel:)
- keyEquivalent:@""];
- [appMenu addItem:[NSMenuItem separatorItem]];
-
- menuItem = [appMenu addItemWithTitle:@"Hide Blender"
- action:@selector(hide:)
- keyEquivalent:@"h"];
- [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
-
- menuItem = [appMenu addItemWithTitle:@"Hide Others"
- action:@selector(hideOtherApplications:)
- keyEquivalent:@"h"];
- [menuItem
- setKeyEquivalentModifierMask:(NSEventModifierFlagOption | NSEventModifierFlagCommand)];
-
- [appMenu addItemWithTitle:@"Show All"
- action:@selector(unhideAllApplications:)
- keyEquivalent:@""];
-
- menuItem = [appMenu addItemWithTitle:@"Quit Blender"
- action:@selector(terminate:)
- keyEquivalent:@"q"];
- [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
-
- menuItem = [[NSMenuItem alloc] init];
- [menuItem setSubmenu:appMenu];
-
- [mainMenubar addItem:menuItem];
- [menuItem release];
- [NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu]; // Needed for 10.5
- [appMenu release];
-
- // Create the window menu
- windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
-
- menuItem = [windowMenu addItemWithTitle:@"Minimize"
- action:@selector(performMiniaturize:)
- keyEquivalent:@"m"];
- [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
-
- [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
-
- menuItem = [windowMenu addItemWithTitle:@"Enter Full Screen"
- action:@selector(toggleFullScreen:)
- keyEquivalent:@"f"];
- [menuItem
- setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
-
- menuItem = [windowMenu addItemWithTitle:@"Close"
- action:@selector(performClose:)
- keyEquivalent:@"w"];
- [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
-
- menuItem = [[NSMenuItem alloc] init];
- [menuItem setSubmenu:windowMenu];
-
- [mainMenubar addItem:menuItem];
- [menuItem release];
-
- [NSApp setMainMenu:mainMenubar];
- [NSApp setWindowsMenu:windowMenu];
- [windowMenu release];
- }
-
- if ([NSApp delegate] == nil) {
- CocoaAppDelegate *appDelegate = [[CocoaAppDelegate alloc] init];
- [appDelegate setSystemCocoa:this];
- [NSApp setDelegate:appDelegate];
- }
+ @autoreleasepool {
+ [NSApplication sharedApplication]; // initializes NSApp
+
+ if ([NSApp mainMenu] == nil) {
+ NSMenu *mainMenubar = [[NSMenu alloc] init];
+ NSMenuItem *menuItem;
+ NSMenu *windowMenu;
+ NSMenu *appMenu;
+
+ // Create the application menu
+ appMenu = [[NSMenu alloc] initWithTitle:@"Blender"];
+
+ [appMenu addItemWithTitle:@"About Blender"
+ action:@selector(orderFrontStandardAboutPanel:)
+ keyEquivalent:@""];
+ [appMenu addItem:[NSMenuItem separatorItem]];
+
+ menuItem = [appMenu addItemWithTitle:@"Hide Blender"
+ action:@selector(hide:)
+ keyEquivalent:@"h"];
+ [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
+
+ menuItem = [appMenu addItemWithTitle:@"Hide Others"
+ action:@selector(hideOtherApplications:)
+ keyEquivalent:@"h"];
+ [menuItem
+ setKeyEquivalentModifierMask:(NSEventModifierFlagOption | NSEventModifierFlagCommand)];
+
+ [appMenu addItemWithTitle:@"Show All"
+ action:@selector(unhideAllApplications:)
+ keyEquivalent:@""];
+
+ menuItem = [appMenu addItemWithTitle:@"Quit Blender"
+ action:@selector(terminate:)
+ keyEquivalent:@"q"];
+ [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
+
+ menuItem = [[NSMenuItem alloc] init];
+ [menuItem setSubmenu:appMenu];
+
+ [mainMenubar addItem:menuItem];
+ [menuItem release];
+ [NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu]; // Needed for 10.5
+ [appMenu release];
+
+ // Create the window menu
+ windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
+
+ menuItem = [windowMenu addItemWithTitle:@"Minimize"
+ action:@selector(performMiniaturize:)
+ keyEquivalent:@"m"];
+ [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
+
+ [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
+
+ menuItem = [windowMenu addItemWithTitle:@"Enter Full Screen"
+ action:@selector(toggleFullScreen:)
+ keyEquivalent:@"f"];
+ [menuItem
+ setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
+
+ menuItem = [windowMenu addItemWithTitle:@"Close"
+ action:@selector(performClose:)
+ keyEquivalent:@"w"];
+ [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
+
+ menuItem = [[NSMenuItem alloc] init];
+ [menuItem setSubmenu:windowMenu];
+
+ [mainMenubar addItem:menuItem];
+ [menuItem release];
+
+ [NSApp setMainMenu:mainMenubar];
+ [NSApp setWindowsMenu:windowMenu];
+ [windowMenu release];
+ }
- // AppKit provides automatic window tabbing. Blender is a single-tabbed application without a
- // macOS tab bar, and should explicitly opt-out of this. This is also controlled by the macOS
- // user default #NSWindowTabbingEnabled.
- NSWindow.allowsAutomaticWindowTabbing = NO;
+ if ([NSApp delegate] == nil) {
+ CocoaAppDelegate *appDelegate = [[CocoaAppDelegate alloc] init];
+ [appDelegate setSystemCocoa:this];
+ [NSApp setDelegate:appDelegate];
+ }
- [NSApp finishLaunching];
+ // AppKit provides automatic window tabbing. Blender is a single-tabbed application
+ // without a macOS tab bar, and should explicitly opt-out of this. This is also
+ // controlled by the macOS user default #NSWindowTabbingEnabled.
+ NSWindow.allowsAutomaticWindowTabbing = NO;
- [pool drain];
+ [NSApp finishLaunching];
+ }
}
return success;
}
@@ -676,30 +675,27 @@ GHOST_TUns8 GHOST_SystemCocoa::getNumDisplays() const
{
// Note that OS X supports monitor hot plug
// We do not support multiple monitors at the moment
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- GHOST_TUns8 count = [[NSScreen screens] count];
-
- [pool drain];
+ @autoreleasepool {
+ GHOST_TUns8 count = [[NSScreen screens] count];
+ }
return count;
}
void GHOST_SystemCocoa::getMainDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- // Get visible frame, that is frame excluding dock and top menu bar
- NSRect frame = [[NSScreen mainScreen] visibleFrame];
-
- // Returns max window contents (excluding title bar...)
- NSRect contentRect = [NSWindow
- contentRectForFrameRect:frame
- styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
- NSWindowStyleMaskMiniaturizable)];
-
- width = contentRect.size.width;
- height = contentRect.size.height;
-
- [pool drain];
+ @autoreleasepool {
+ // Get visible frame, that is frame excluding dock and top menu bar
+ NSRect frame = [[NSScreen mainScreen] visibleFrame];
+
+ // Returns max window contents (excluding title bar...)
+ NSRect contentRect = [NSWindow
+ contentRectForFrameRect:frame
+ styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
+ NSWindowStyleMaskMiniaturizable)];
+
+ width = contentRect.size.width;
+ height = contentRect.size.height;
+ }
}
void GHOST_SystemCocoa::getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const
@@ -720,53 +716,52 @@ GHOST_IWindow *GHOST_SystemCocoa::createWindow(const char *title,
const bool is_dialog,
const GHOST_IWindow *parentWindow)
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
GHOST_IWindow *window = NULL;
-
- // Get the available rect for including window contents
- NSRect frame = [[NSScreen mainScreen] visibleFrame];
- NSRect contentRect = [NSWindow
- contentRectForFrameRect:frame
- styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
- NSWindowSt
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list