Skip to content

Commit

Permalink
Fix build with SDK macosx10.15
Browse files Browse the repository at this point in the history
Change-Id: I54860ea7e81b16037dd21bcb337a85a08e2a17c2
  • Loading branch information
AlienCowEatCake committed Aug 27, 2024
1 parent 372eaed commit 9014504
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mkspecs/common/macx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
QMAKE_PLATFORM += macos osx macx
QMAKE_MAC_SDK = macosx

QMAKE_MACOSX_DEPLOYMENT_TARGET = 11
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.15

QT_MAC_SDK_VERSION_MIN = 11
QT_MAC_SDK_VERSION_MIN = 10.15

QT_MAC_SDK_VERSION_MAX = 14

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,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 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 @@ -122,6 +125,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 @@ -169,9 +175,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
32 changes: 32 additions & 0 deletions src/gui/rhi/qrhimetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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

MTLRenderPassDescriptor *createDefaultRenderPass(bool hasDepthStencil,
const QColor &colorClearValue,
Expand Down Expand Up @@ -450,6 +452,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 @@ -464,6 +467,7 @@ inline Int aligned(Int v, Int byteAlign)
}
return true;
}
#endif
return false;
}

Expand Down Expand Up @@ -492,6 +496,7 @@ inline Int aligned(Int v, Int byteAlign)
#ifdef Q_OS_IOS
driverInfoStruct.deviceType = QRhiDriverInfo::IntegratedDevice;
#else
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(101500)
if (@available(macOS 10.15, *)) {
const MTLDeviceLocation deviceLocation = [d->dev location];
switch (deviceLocation) {
Expand All @@ -508,6 +513,7 @@ inline Int aligned(Int v, Int byteAlign)
break;
}
}
#endif
#endif

const QOperatingSystemVersion ver = QOperatingSystemVersion::current();
Expand All @@ -530,8 +536,10 @@ inline Int aligned(Int v, Int byteAlign)
#if defined(Q_OS_MACOS)
caps.maxTextureSize = 16384;
caps.baseVertexAndInstance = true;
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000)
if (@available(macOS 10.15, *))
caps.isAppleGPU = [d->dev supportsFamily:MTLGPUFamilyApple7];
#endif
caps.maxThreadGroupSize = 1024;
#elif defined(Q_OS_TVOS)
if ([d->dev supportsFeatureSet: MTLFeatureSet(30003)]) // MTLFeatureSet_tvOS_GPUFamily2_v1
Expand Down Expand Up @@ -591,10 +599,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 @@ -753,9 +763,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 @@ -873,6 +885,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 @@ -921,6 +934,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 @@ -970,6 +984,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 @@ -986,6 +1001,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 @@ -3170,6 +3186,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 @@ -3289,6 +3306,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 @@ -3354,12 +3372,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 @@ -4576,16 +4596,19 @@ static inline MTLTessellationPartitionMode toMetalTessellationPartitionMode(QSha

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 @@ -4595,6 +4618,7 @@ static inline MTLTessellationPartitionMode toMetalTessellationPartitionMode(QSha
}
}
}
#endif
}

bool QMetalGraphicsPipeline::createVertexFragmentPipeline()
Expand Down Expand Up @@ -5317,16 +5341,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 @@ -5336,6 +5363,7 @@ static inline bool matches(const QShaderDescription::InOutVariable &a, const QSh
}
}
}
#endif
}

bool QMetalComputePipeline::create()
Expand Down Expand Up @@ -5580,9 +5608,11 @@ static inline bool matches(const QShaderDescription::InOutVariable &a, const QSh
bool QMetalSwapChain::isFormatSupported(Format f)
{
if (f == HDRExtendedSrgbLinear) {
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000)
if (@available(macOS 10.11, iOS 16.0, *))
return true;
else
#endif
return false;
}
return f == SDR;
Expand Down Expand Up @@ -5657,10 +5687,12 @@ static inline bool matches(const QShaderDescription::InOutVariable &a, const QSh
d->layer.pixelFormat = d->colorFormat;

if (m_format == HDRExtendedSrgbLinear) {
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(110000)
if (@available(macOS 10.11, iOS 16.0, *)) {
d->layer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedLinearSRGB);
d->layer.wantsExtendedDynamicRangeContent = YES;
}
#endif
}

if (m_flags.testFlag(UsedAsTransferSource))
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/platforms/cocoa/qcocoamessagedialog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ At this point the options() will reflect the specific dialog shown.
cancelButtonAdded = true;
}

#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),
Expand Down

0 comments on commit 9014504

Please sign in to comment.