From 43888ebfaf622f5617788c16e503723ed39fdf21 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 29 Jun 2020 14:24:56 +0300 Subject: [PATCH] [macOS, 3.2] Add support for the Apple Silicon (ARM64) build target. --- .../dist/osx_template.app/Contents/Info.plist | 10 ++++++-- misc/dist/osx_tools.app/Contents/Info.plist | 12 +++++++--- modules/camera/camera_osx.mm | 5 ++++ modules/opus/SCsub | 3 +++ modules/webm/libvpx/SCsub | 4 +++- platform/osx/detect.py | 18 +++++++++----- platform/osx/os_osx.mm | 24 ++++++++++++++----- 7 files changed, 58 insertions(+), 18 deletions(-) diff --git a/misc/dist/osx_template.app/Contents/Info.plist b/misc/dist/osx_template.app/Contents/Info.plist index 696c825594a..eefaf8e1ad1 100755 --- a/misc/dist/osx_template.app/Contents/Info.plist +++ b/misc/dist/osx_template.app/Contents/Info.plist @@ -30,12 +30,18 @@ $camera_usage_description NSHumanReadableCopyright $copyright + CFBundleSupportedPlatforms + + MacOSX + + NSPrincipalClass + NSApplication LSMinimumSystemVersion - 10.9.0 + 10.9 LSMinimumSystemVersionByArchitecture x86_64 - 10.9.0 + 10.9 NSHighResolutionCapable $highres diff --git a/misc/dist/osx_tools.app/Contents/Info.plist b/misc/dist/osx_tools.app/Contents/Info.plist index 159da838f3d..28d9d4aa7d0 100755 --- a/misc/dist/osx_tools.app/Contents/Info.plist +++ b/misc/dist/osx_tools.app/Contents/Info.plist @@ -29,15 +29,21 @@ NSCameraUsageDescription Camera access is required to capture video. NSRequiresAquaSystemAppearance - + NSHumanReadableCopyright © 2007-2020 Juan Linietsky, Ariel Manzur & Godot Engine contributors + CFBundleSupportedPlatforms + + MacOSX + + NSPrincipalClass + NSApplication LSMinimumSystemVersion - 10.9.0 + 10.9 LSMinimumSystemVersionByArchitecture x86_64 - 10.9.0 + 10.9 NSHighResolutionCapable diff --git a/modules/camera/camera_osx.mm b/modules/camera/camera_osx.mm index 658ddb728b6..11b2498ada5 100644 --- a/modules/camera/camera_osx.mm +++ b/modules/camera/camera_osx.mm @@ -313,7 +313,12 @@ MyDeviceNotifications *device_notifications = nil; // CameraOSX - Subclass for our camera server on OSX void CameraOSX::update_feeds() { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101500 + AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:[NSArray arrayWithObjects:AVCaptureDeviceTypeExternalUnknown, AVCaptureDeviceTypeBuiltInWideAngleCamera, nil] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified]; + NSArray *devices = session.devices; +#else NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; +#endif // remove devices that are gone.. for (int i = feeds.size() - 1; i >= 0; i--) { diff --git a/modules/opus/SCsub b/modules/opus/SCsub index e51590d8083..52c61fa7080 100644 --- a/modules/opus/SCsub +++ b/modules/opus/SCsub @@ -227,6 +227,9 @@ if env["builtin_opus"]: env_opus.Append(CPPDEFINES=["OPUS_ARM_OPT"]) elif "arch" in env and env["arch"] == "arm64": env_opus.Append(CPPDEFINES=["OPUS_ARM64_OPT"]) + elif env["platform"] == "osx": + if "arch" in env and env["arch"] == "arm64": + env_opus.Append(CPPDEFINES=["OPUS_ARM64_OPT"]) env_thirdparty = env_opus.Clone() env_thirdparty.disable_warnings() diff --git a/modules/webm/libvpx/SCsub b/modules/webm/libvpx/SCsub index e85d430861b..7aaa4a9fa96 100644 --- a/modules/webm/libvpx/SCsub +++ b/modules/webm/libvpx/SCsub @@ -230,6 +230,7 @@ else: is_x11_or_server_arm = (env["platform"] == "x11" or env["platform"] == "server") and ( platform.machine().startswith("arm") or platform.machine().startswith("aarch") ) + is_macos_x86 = env["platform"] == "osx" and ("arch" in env and (env["arch"] != "arm64")) is_ios_x86 = env["platform"] == "iphone" and ("arch" in env and env["arch"].startswith("x86")) is_android_x86 = env["platform"] == "android" and env["android_arch"].startswith("x86") if is_android_x86: @@ -240,14 +241,15 @@ else: and ( env["platform"] == "windows" or env["platform"] == "x11" - or env["platform"] == "osx" or env["platform"] == "haiku" + or is_macos_x86 or is_android_x86 or is_ios_x86 ) ) webm_cpu_arm = ( is_x11_or_server_arm + or (not is_macos_x86 and env["platform"] == "osx") or (not is_ios_x86 and env["platform"] == "iphone") or (not is_android_x86 and env["platform"] == "android") ) diff --git a/platform/osx/detect.py b/platform/osx/detect.py index 27dc58c26c2..2160736b6c5 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -81,8 +81,15 @@ def configure(env): env["osxcross"] = True if not "osxcross" in env: # regular native build - env.Append(CCFLAGS=["-arch", "x86_64"]) - env.Append(LINKFLAGS=["-arch", "x86_64"]) + if env["arch"] == "arm64": + print("Building for macOS 10.15+, platform arm64.") + env.Append(CCFLAGS=["-arch", "arm64", "-mmacosx-version-min=10.15", "-target", "arm64-apple-macos10.15"]) + env.Append(LINKFLAGS=["-arch", "arm64", "-mmacosx-version-min=10.15", "-target", "arm64-apple-macos10.15"]) + else: + print("Building for macOS 10.9+, platform x86-64.") + env.Append(CCFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.9"]) + env.Append(LINKFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.9"]) + if env["macports_clang"] != "no": mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local") mpclangver = env["macports_clang"] @@ -142,7 +149,8 @@ def configure(env): ## Dependencies if env["builtin_libtheora"]: - env["x86_libtheora_opt_gcc"] = True + if env["arch"] != "arm64": + env["x86_libtheora_opt_gcc"] = True ## Flags @@ -155,6 +163,7 @@ def configure(env): "APPLE_STYLE_KEYS", "COREAUDIO_ENABLED", "COREMIDI_ENABLED", + "GL_SILENCE_DEPRECATION", ] ) env.Append( @@ -187,6 +196,3 @@ def configure(env): ] ) env.Append(LIBS=["pthread"]) - - env.Append(CCFLAGS=["-mmacosx-version-min=10.9"]) - env.Append(LINKFLAGS=["-mmacosx-version-min=10.9"]) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index d183a759ee1..54fb302bf3f 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -444,7 +444,7 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) { @end -@interface GodotContentView : NSView { +@interface GodotContentView : NSOpenGLView { NSTrackingArea *trackingArea; NSMutableAttributedString *markedText; bool imeInputEventInProgress; @@ -475,7 +475,11 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) { trackingArea = nil; imeInputEventInProgress = false; [self updateTrackingAreas]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 + [self registerForDraggedTypes:[NSArray arrayWithObject:NSPasteboardTypeFileURL]]; +#else [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]]; +#endif markedText = [[NSMutableAttributedString alloc] init]; return self; } @@ -619,11 +623,19 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (BOOL)performDragOperation:(id)sender { NSPasteboard *pboard = [sender draggingPasteboard]; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 + NSArray *filenames = [pboard propertyListForType:NSPasteboardTypeFileURL]; +#else NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType]; +#endif Vector files; for (NSUInteger i = 0; i < filenames.count; i++) { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 + NSString *ns = [[filenames objectAtIndex:i] path]; +#else NSString *ns = [filenames objectAtIndex:i]; +#endif char *utfs = strdup([ns UTF8String]); String ret; ret.parse_utf8(utfs); @@ -712,7 +724,7 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) { const Vector2 pos = get_mouse_pos([event locationInWindow], backingScaleFactor); mm->set_position(pos); mm->set_pressure([event pressure]); - if ([event subtype] == NSTabletPointEventSubtype) { + if ([event subtype] == NSEventSubtypeTabletPoint) { const NSPoint p = [event tilt]; mm->set_tilt(Vector2(p.x, p.y)); } @@ -1600,7 +1612,7 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a ERR_FAIL_COND_V(context == nil, ERR_UNAVAILABLE); - [context setView:window_view]; + [window_view setOpenGLContext:context]; [context makeCurrentContext]; @@ -1800,7 +1812,7 @@ void OS_OSX::alert(const String &p_alert, const String &p_title) { [window addButtonWithTitle:@"OK"]; [window setMessageText:ns_title]; [window setInformativeText:ns_alert]; - [window setAlertStyle:NSWarningAlertStyle]; + [window setAlertStyle:NSAlertStyleWarning]; // Display it, then release [window runModal]; @@ -2686,14 +2698,14 @@ void OS_OSX::set_window_per_pixel_transparency_enabled(bool p_enabled) { [window_object setBackgroundColor:[NSColor clearColor]]; [window_object setOpaque:NO]; [window_object setHasShadow:NO]; - [context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity]; + [context setValues:&opacity forParameter:NSOpenGLContextParameterSurfaceOpacity]; layered_window = true; } else { GLint opacity = 1; [window_object setBackgroundColor:[NSColor colorWithCalibratedWhite:1 alpha:1]]; [window_object setOpaque:YES]; [window_object setHasShadow:YES]; - [context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity]; + [context setValues:&opacity forParameter:NSOpenGLContextParameterSurfaceOpacity]; layered_window = false; } [context update];