From 18ba81aee6f835346a56dbb3746ad771eaa73bed Mon Sep 17 00:00:00 2001 From: Peter Zhigalov Date: Wed, 19 Jun 2024 04:39:12 +0700 Subject: [PATCH] Fix build with SDK macosx10.15 Change-Id: I460edced05d5404bdf7fab386936f19b720814a8 --- cmake/QtFrameworkHelpers.cmake | 10 +++++ .../qdarwinpermissionplugin_location.mm | 8 ++++ src/gui/platform/darwin/qappleiconengine.mm | 42 ++++++++++++------- src/gui/rhi/qrhimetal.mm | 34 ++++++++++++++- .../cocoa/qcocoaapplicationdelegate.mm | 2 + .../platforms/cocoa/qcocoafiledialoghelper.mm | 26 ++++++++---- .../platforms/cocoa/qcocoamessagedialog.mm | 2 + src/plugins/platforms/cocoa/qcocoawindow.mm | 24 +++++++---- 8 files changed, 116 insertions(+), 32 deletions(-) diff --git a/cmake/QtFrameworkHelpers.cmake b/cmake/QtFrameworkHelpers.cmake index 0f776ec0dbb..51b50cf2945 100644 --- a/cmake/QtFrameworkHelpers.cmake +++ b/cmake/QtFrameworkHelpers.cmake @@ -53,6 +53,16 @@ function(qt_internal_find_apple_system_framework out_var framework_name) find_library(${cache_var_name} "${framework_name}") + # Dirty hack for 10.15 build + if("${framework_name}" STREQUAL "UniformTypeIdentifiers") + if(${cache_var_name} AND NOT ${cache_var_name} MATCHES "^/System/Library/Frameworks.*") + set(${out_var} "-weak_framework ${framework_name}" PARENT_SCOPE) + else() + set(${out_var} "" PARENT_SCOPE) + endif() + return() + endif() + if(${cache_var_name} AND ${cache_var_name} MATCHES ".framework$") set(${out_var} "-framework ${framework_name}" PARENT_SCOPE) else() diff --git a/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm b/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm index 1d32c0fcacb..3859619c2c0 100644 --- a/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm +++ b/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm @@ -104,8 +104,10 @@ - (instancetype)init - (CLAuthorizationStatus)authorizationStatus { if (self.manager) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11, iOS 14, *)) return self.manager.authorizationStatus; +#endif } return QT_IGNORE_DEPRECATIONS(CLLocationManager.authorizationStatus); @@ -113,6 +115,7 @@ - (CLAuthorizationStatus)authorizationStatus - (Qt::PermissionStatus)accuracyAuthorization:(QLocationPermission)permission { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) auto status = CLAccuracyAuthorizationReducedAccuracy; if (@available(macOS 11, iOS 14, *)) status = self.manager.accuracyAuthorization; @@ -129,6 +132,9 @@ - (CLAuthorizationStatus)authorizationStatus qCWarning(lcPermissions) << "Unknown accuracy status" << status << "detected in" << self; return Qt::PermissionStatus::Denied; +#else + return Qt::PermissionStatus::Granted; +#endif } - (QStringList)usageDescriptionsFor:(QPermission)permission @@ -176,9 +182,11 @@ - (void)requestQueuedPermission // The documentation specifies that requestWhenInUseAuthorization can // only be called when the current authorization status is undetermined. switch ([self authorizationStatus]) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) case kCLAuthorizationStatusNotDetermined: [self.manager requestWhenInUseAuthorization]; break; +#endif default: [self deliverResult]; } diff --git a/src/gui/platform/darwin/qappleiconengine.mm b/src/gui/platform/darwin/qappleiconengine.mm index d99da6da841..579721c816e 100644 --- a/src/gui/platform/darwin/qappleiconengine.mm +++ b/src/gui/platform/darwin/qappleiconengine.mm @@ -279,7 +279,12 @@ }); NSString *systemIconName = it != std::end(iconMap) ? it->second : iconName.toNSString(); #if defined(Q_OS_MACOS) - return [NSImage imageWithSystemSymbolName:systemIconName accessibilityDescription:nil]; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) + if (@available(macOS 11.0, *)) { + return [NSImage imageWithSystemSymbolName:systemIconName accessibilityDescription:nil]; + } +#endif + return (NSImage *)nil; #elif defined(QT_PLATFORM_UIKIT) return [UIImage systemImageNamed:systemIconName]; #endif @@ -357,22 +362,29 @@ namespace { #if defined(Q_OS_MACOS) -auto *configuredImage(const NSImage *image, const QColor &color) +const auto *configuredImage(const NSImage *image, const QColor &color) { - auto *config = [NSImageSymbolConfiguration configurationWithPointSize:48 - weight:NSFontWeightRegular - scale:NSImageSymbolScaleLarge]; - if (@available(macOS 12, *)) { - auto *primaryColor = [NSColor colorWithSRGBRed:color.redF() - green:color.greenF() - blue:color.blueF() - alpha:color.alphaF()]; - - auto *colorConfig = [NSImageSymbolConfiguration configurationWithHierarchicalColor:primaryColor]; - config = [config configurationByApplyingConfiguration:colorConfig]; - } +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) + if (@available(macOS 11, *)) { + auto *config = [NSImageSymbolConfiguration configurationWithPointSize:48 + weight:NSFontWeightRegular + scale:NSImageSymbolScaleLarge]; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(120000) + if (@available(macOS 12, *)) { + auto *primaryColor = [NSColor colorWithSRGBRed:color.redF() + green:color.greenF() + blue:color.blueF() + alpha:color.alphaF()]; + + auto *colorConfig = [NSImageSymbolConfiguration configurationWithHierarchicalColor:primaryColor]; + config = [config configurationByApplyingConfiguration:colorConfig]; + } +#endif - return [image imageWithSymbolConfiguration:config]; + return [image imageWithSymbolConfiguration:config]; + } +#endif + return image; } #elif defined(QT_PLATFORM_UIKIT) auto *configuredImage(const UIImage *image, const QColor &color) diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index a5edb2a9265..267faed40dd 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -173,7 +173,9 @@ void destroy() { QRhiMetal *q; id dev = nil; id cmdQueue = nil; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) API_AVAILABLE(macosx(11.0), ios(14.0)) id binArch = nil; +#endif id newCommandBuffer(); MTLRenderPassDescriptor *createDefaultRenderPass(bool hasDepthStencil, @@ -528,6 +530,7 @@ inline Int aligned(Int v, Int byteAlign) return false; #endif +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) { [binArch release]; MTLBinaryArchiveDescriptor *binArchDesc = [MTLBinaryArchiveDescriptor new]; @@ -542,6 +545,7 @@ inline Int aligned(Int v, Int byteAlign) } return true; } +#endif return false; } @@ -567,7 +571,7 @@ inline Int aligned(Int v, Int byteAlign) // suitable as deviceId because it does not seem stable on macOS and can // apparently change when the system is rebooted. -#ifdef Q_OS_MACOS +#if defined(Q_OS_MACOS) && QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(101500) if (@available(macOS 10.15, *)) { const MTLDeviceLocation deviceLocation = [d->dev location]; switch (deviceLocation) { @@ -608,8 +612,10 @@ inline Int aligned(Int v, Int byteAlign) #if defined(Q_OS_MACOS) caps.maxTextureSize = 16384; caps.baseVertexAndInstance = true; - if (@available(macOS 10.15, *)) +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) + if (@available(macOS 11.0, *)) caps.isAppleGPU = [d->dev supportsFamily:MTLGPUFamilyApple7]; +#endif caps.maxThreadGroupSize = 1024; caps.multiView = true; #elif defined(Q_OS_TVOS) @@ -666,10 +672,12 @@ inline Int aligned(Int v, Int byteAlign) [d->captureScope release]; d->captureScope = nil; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) { [d->binArch release]; d->binArch = nil; } +#endif [d->cmdQueue release]; if (!importedCmdQueue) @@ -817,9 +825,11 @@ inline Int aligned(Int v, Int byteAlign) return true; case QRhi::PipelineCacheDataLoadSave: { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) return true; else +#endif return false; } case QRhi::ImageDataStride: @@ -949,6 +959,7 @@ inline Int aligned(Int v, Int byteAlign) { Q_STATIC_ASSERT(sizeof(QMetalPipelineCacheDataHeader) == 256); QByteArray data; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) { if (!d->binArch || !rhiFlags.testFlag(QRhi::EnablePipelineCacheDataSave)) return data; @@ -997,6 +1008,7 @@ inline Int aligned(Int v, Int byteAlign) memcpy(data.data(), &header, headerSize); memcpy(data.data() + headerSize, blob.constData(), dataSize); } +#endif return data; } @@ -1046,6 +1058,7 @@ inline Int aligned(Int v, Int byteAlign) return; } +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) { const char *p = data.constData() + dataOffset; @@ -1062,6 +1075,7 @@ inline Int aligned(Int v, Int byteAlign) if (d->setupBinaryArchive(url)) qCDebug(QRHI_LOG_INFO, "Created MTLBinaryArchive with initial data of %u bytes", header.dataSize); } +#endif } QRhiRenderBuffer *QRhiMetal::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, @@ -3523,6 +3537,7 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR case QRhiTexture::ASTC_12x12: return srgb ? MTLPixelFormatASTC_12x12_sRGB : MTLPixelFormatASTC_12x12_LDR; #else +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) case QRhiTexture::ETC2_RGB8: if (d->caps.isAppleGPU) { if (@available(macOS 11.0, *)) @@ -3642,6 +3657,7 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR } qWarning("QRhiMetal: ASTC compression not supported on this platform"); return MTLPixelFormatInvalid; +#endif #endif default: @@ -3707,12 +3723,14 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR case DepthStencil: #ifdef Q_OS_MACOS if (rhiD->caps.isAppleGPU) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, *)) { desc.storageMode = MTLStorageModeMemoryless; d->format = MTLPixelFormatDepth32Float_Stencil8; } else { Q_UNREACHABLE(); } +#endif } else { desc.storageMode = MTLStorageModePrivate; d->format = rhiD->d->dev.depth24Stencil8PixelFormatSupported @@ -5000,16 +5018,19 @@ static inline MTLLanguageVersion toMetalLanguageVersion(const QShaderVersion &ve void QRhiMetalData::trySeedingRenderPipelineFromBinaryArchive(MTLRenderPipelineDescriptor *rpDesc) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) { if (binArch) { NSArray *binArchArray = [NSArray arrayWithObjects: binArch, nil]; rpDesc.binaryArchives = binArchArray; } } +#endif } void QRhiMetalData::addRenderPipelineToBinaryArchive(MTLRenderPipelineDescriptor *rpDesc) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) { if (binArch) { NSError *err = nil; @@ -5019,6 +5040,7 @@ static inline MTLLanguageVersion toMetalLanguageVersion(const QShaderVersion &ve } } } +#endif } bool QMetalGraphicsPipeline::createVertexFragmentPipeline() @@ -5986,16 +6008,19 @@ static inline bool matches(const QShaderDescription::InOutVariable &a, const QSh void QRhiMetalData::trySeedingComputePipelineFromBinaryArchive(MTLComputePipelineDescriptor *cpDesc) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) { if (binArch) { NSArray *binArchArray = [NSArray arrayWithObjects: binArch, nil]; cpDesc.binaryArchives = binArchArray; } } +#endif } void QRhiMetalData::addComputePipelineToBinaryArchive(MTLComputePipelineDescriptor *cpDesc) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) { if (binArch) { NSError *err = nil; @@ -6005,6 +6030,7 @@ static inline bool matches(const QShaderDescription::InOutVariable &a, const QSh } } } +#endif } bool QMetalComputePipeline::create() @@ -6278,9 +6304,11 @@ static inline bool matches(const QShaderDescription::InOutVariable &a, const QSh else return false; } else if (f == HDRExtendedDisplayP3Linear) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 14.0, *)) return hdrInfo().limits.colorComponentValue.maxPotentialColorComponentValue > 1.0f; else +#endif return false; } return f == SDR; @@ -6371,10 +6399,12 @@ static inline bool matches(const QShaderDescription::InOutVariable &a, const QSh d->layer.wantsExtendedDynamicRangeContent = YES; } } else if (m_format == HDRExtendedDisplayP3Linear) { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11.0, iOS 16.0, *)) { d->layer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedLinearDisplayP3); d->layer.wantsExtendedDynamicRangeContent = YES; } +#endif } if (m_flags.testFlag(UsedAsTransferSource)) diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index fc871be5f32..1a9a6dbbac0 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -393,10 +393,12 @@ - (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescr - (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)application { +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(120000) if (@available(macOS 12, *)) { if ([reflectionDelegate respondsToSelector:_cmd]) return [reflectionDelegate applicationSupportsSecureRestorableState:application]; } +#endif // We don't support or implement state restorations via the AppKit // state restoration APIs, but if we did, we would/should support diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 41170b74eaa..c9ea202201f 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -25,7 +25,9 @@ #include #include +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) #include +#endif QT_USE_NAMESPACE @@ -305,7 +307,11 @@ - (BOOL)panel:(id)sender validateURL:(NSURL *)url error:(NSError * _Nullable *)o fileInfo.absoluteDir().dirName().toNSString()]; auto *replaceButton = [alert addButtonWithTitle:qt_mac_AppKitString(@"SavePanel", @"Replace")]; - replaceButton.hasDestructiveAction = YES; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) + if (@available(macOS 11, *)) { + replaceButton.hasDestructiveAction = YES; + } +#endif replaceButton.tag = 1337; [alert addButtonWithTitle:qt_mac_AppKitString(@"Common", @"Cancel")]; @@ -454,15 +460,19 @@ - (void)updateProperties // We work around this by temporarily resetting the allowed // content type to one without an extension, which forces // the save panel to update and remove the extension. - const bool nameFieldHasExtension = m_panel.nameFieldStringValue.pathExtension.length > 0; - if (!m_panel.allowedFileTypes && !nameFieldHasExtension && !openpanel_cast(m_panel)) { - if (!UTTypeDirectory.preferredFilenameExtension) { - m_panel.allowedContentTypes = @[ UTTypeDirectory ]; - m_panel.allowedFileTypes = nil; - } else { - qWarning() << "UTTypeDirectory unexpectedly reported an extension"; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) + if (@available(macOS 11.0, *)) { + const bool nameFieldHasExtension = m_panel.nameFieldStringValue.pathExtension.length > 0; + if (!m_panel.allowedFileTypes && !nameFieldHasExtension && !openpanel_cast(m_panel)) { + if (!UTTypeDirectory.preferredFilenameExtension) { + m_panel.allowedContentTypes = @[ UTTypeDirectory ]; + m_panel.allowedFileTypes = nil; + } else { + qWarning() << "UTTypeDirectory unexpectedly reported an extension"; + } } } +#endif m_panel.showsHiddenFiles = m_options->filter().testFlag(QDir::Hidden); diff --git a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm index 84525099c96..cfc73e67938 100644 --- a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm +++ b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm @@ -170,8 +170,10 @@ At this point the options() will reflect the specific dialog shown. else if ([button.keyEquivalent isEqualToString:@"\e"]) button.keyEquivalent = @""; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) if (@available(macOS 11, *)) button.hasDestructiveAction = role == DestructiveRole; +#endif // The NSModalResponse of showing an NSAlert normally depends on the order of the // button that was clicked, starting from the right with NSAlertFirstButtonReturn (1000), diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index b4c8ae4ba1f..e86777d1312 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -293,19 +293,29 @@ a normal (not maximized or full screen) top-level window. // the current view (by setting additionalSafeAreaInsets). If the window // uses NSWindowStyleMaskFullSizeContentView this also includes the area // of the view covered by the title bar. - QMarginsF viewSafeAreaMargins = { - m_view.safeAreaInsets.left, - m_view.safeAreaInsets.top, - m_view.safeAreaInsets.right, - m_view.safeAreaInsets.bottom - }; + QMarginsF viewSafeAreaMargins; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000) + if (@available(macOS 11, *)) { + viewSafeAreaMargins = { + m_view.safeAreaInsets.left, + m_view.safeAreaInsets.top, + m_view.safeAreaInsets.right, + m_view.safeAreaInsets.bottom + }; + } +#endif // The screen's safe area insets represent the distances from the screen's // edges at which content isn't obscured. The view's safe area margins do // not include the screen's insets automatically, so we need to manually // merge them. auto screenRect = m_view.window.screen.frame; - auto screenInsets = m_view.window.screen.safeAreaInsets; + NSEdgeInsets screenInsets = NSEdgeInsetsZero; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(120000) + if (@available(macOS 12, *)) { + screenInsets = m_view.window.screen.safeAreaInsets; + } +#endif auto screenRelativeViewBounds = QCocoaScreen::mapFromNative( [m_view.window convertRectToScreen: [m_view convertRect:m_view.bounds toView:nil]]