Skip to content

Commit

Permalink
Fix build with SDK macosx10.15
Browse files Browse the repository at this point in the history
Change-Id: I460edced05d5404bdf7fab386936f19b720814a8
  • Loading branch information
AlienCowEatCake committed Oct 19, 2024
1 parent e407bab commit 18ba81a
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 32 deletions.
10 changes: 10 additions & 0 deletions cmake/QtFrameworkHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,18 @@ - (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);
}

- (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;
Expand All @@ -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
Expand Down Expand Up @@ -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];
}
Expand Down
42 changes: 27 additions & 15 deletions src/gui/platform/darwin/qappleiconengine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 32 additions & 2 deletions src/gui/rhi/qrhimetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ void destroy() {
QRhiMetal *q;
id<MTLDevice> dev = nil;
id<MTLCommandQueue> cmdQueue = nil;
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000)
API_AVAILABLE(macosx(11.0), ios(14.0)) id<MTLBinaryArchive> binArch = nil;
#endif

id<MTLCommandBuffer> newCommandBuffer();
MTLRenderPassDescriptor *createDefaultRenderPass(bool hasDepthStencil,
Expand Down Expand Up @@ -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];
Expand All @@ -542,6 +545,7 @@ inline Int aligned(Int v, Int byteAlign)
}
return true;
}
#endif
return false;
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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, *))
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -5019,6 +5040,7 @@ static inline MTLLanguageVersion toMetalLanguageVersion(const QShaderVersion &ve
}
}
}
#endif
}

bool QMetalGraphicsPipeline::createVertexFragmentPipeline()
Expand Down Expand Up @@ -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;
Expand All @@ -6005,6 +6030,7 @@ static inline bool matches(const QShaderDescription::InOutVariable &a, const QSh
}
}
}
#endif
}

bool QMetalComputePipeline::create()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 18 additions & 8 deletions src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include <qpa/qplatformtheme.h>
#include <qpa/qplatformnativeinterface.h>

#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000)
#include <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
#endif

QT_USE_NAMESPACE

Expand Down Expand Up @@ -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")];

Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 18ba81a

Please sign in to comment.