SDL: Fixed Xcode warnings (48120)

From 481203c074d4a854e26051f757543abbf4df98c6 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 18 Sep 2024 13:20:53 -0700
Subject: [PATCH] Fixed Xcode warnings

---
 src/gpu/metal/SDL_gpu_metal.m             | 50 ++++++++++++++++-------
 src/hidapi/mac/hid.c                      |  2 +-
 src/process/posix/SDL_posixprocess.c      |  2 +-
 src/video/cocoa/SDL_cocoapen.m            |  2 +-
 src/video/uikit/SDL_uikitviewcontroller.m | 10 ++---
 5 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/src/gpu/metal/SDL_gpu_metal.m b/src/gpu/metal/SDL_gpu_metal.m
index 95a400a790b3f..7992055fefb10 100644
--- a/src/gpu/metal/SDL_gpu_metal.m
+++ b/src/gpu/metal/SDL_gpu_metal.m
@@ -1198,8 +1198,10 @@ static void METAL_InsertDebugLabel(
             [metalCommandBuffer->computeEncoder insertDebugSignpost:label];
         } else {
             // Metal doesn't have insertDebugSignpost for command buffers...
-            [metalCommandBuffer->handle pushDebugGroup:label];
-            [metalCommandBuffer->handle popDebugGroup];
+            if (@available(macOS 10.13, *)) {
+                [metalCommandBuffer->handle pushDebugGroup:label];
+                [metalCommandBuffer->handle popDebugGroup];
+            }
         }
     }
 }
@@ -1219,7 +1221,9 @@ static void METAL_PushDebugGroup(
         } else if (metalCommandBuffer->computeEncoder) {
             [metalCommandBuffer->computeEncoder pushDebugGroup:label];
         } else {
-            [metalCommandBuffer->handle pushDebugGroup:label];
+            if (@available(macOS 10.13, *)) {
+                [metalCommandBuffer->handle pushDebugGroup:label];
+            }
         }
     }
 }
@@ -1237,7 +1241,9 @@ static void METAL_PopDebugGroup(
         } else if (metalCommandBuffer->computeEncoder) {
             [metalCommandBuffer->computeEncoder popDebugGroup];
         } else {
-            [metalCommandBuffer->handle popDebugGroup];
+            if (@available(macOS 10.13, *)) {
+                [metalCommandBuffer->handle popDebugGroup];
+            }
         }
     }
 }
@@ -1321,11 +1327,15 @@ static void METAL_PopDebugGroup(
     textureDescriptor.pixelFormat = SDLToMetal_SurfaceFormat[createinfo->format];
     // This format isn't natively supported so let's swizzle!
     if (createinfo->format == SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM) {
-        textureDescriptor.swizzle = MTLTextureSwizzleChannelsMake(
-            MTLTextureSwizzleBlue,
-            MTLTextureSwizzleGreen,
-            MTLTextureSwizzleRed,
-            MTLTextureSwizzleAlpha);
+        if (@available(macOS 10.15, *)) {
+            textureDescriptor.swizzle = MTLTextureSwizzleChannelsMake(MTLTextureSwizzleBlue,
+                                                                      MTLTextureSwizzleGreen,
+                                                                      MTLTextureSwizzleRed,
+                                                                      MTLTextureSwizzleAlpha);
+        } else {
+            SDL_SetError("SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM is not supported");
+            return NULL;
+        }
     }
 
     textureDescriptor.width = createinfo->width;
@@ -3409,7 +3419,9 @@ static Uint8 METAL_INTERNAL_CreateSwapchain(
     windowData->layer = (__bridge CAMetalLayer *)(SDL_Metal_GetLayer(windowData->view));
     windowData->layer.device = renderer->device;
 #ifdef SDL_PLATFORM_MACOS
-    windowData->layer.displaySyncEnabled = (presentMode != SDL_GPU_PRESENTMODE_IMMEDIATE);
+    if (@available(macOS 10.13, *)) {
+        windowData->layer.displaySyncEnabled = (presentMode != SDL_GPU_PRESENTMODE_IMMEDIATE);
+    }
 #endif
     windowData->layer.pixelFormat = SDLToMetal_SurfaceFormat[SwapchainCompositionToFormat[swapchainComposition]];
 #ifndef SDL_PLATFORM_TVOS
@@ -3632,7 +3644,9 @@ static bool METAL_SetSwapchainParameters(
         METAL_Wait(driverData);
 
 #ifdef SDL_PLATFORM_MACOS
-        windowData->layer.displaySyncEnabled = (presentMode != SDL_GPU_PRESENTMODE_IMMEDIATE);
+        if (@available(macOS 10.13, *)) {
+            windowData->layer.displaySyncEnabled = (presentMode != SDL_GPU_PRESENTMODE_IMMEDIATE);
+        }
 #endif
         windowData->layer.pixelFormat = SDLToMetal_SurfaceFormat[SwapchainCompositionToFormat[swapchainComposition]];
 #ifndef SDL_PLATFORM_TVOS
@@ -3763,8 +3777,12 @@ static bool METAL_SupportsTextureFormat(
 
         // Cube arrays are not supported on older iOS devices
         if (type == SDL_GPU_TEXTURETYPE_CUBE_ARRAY) {
-            if (!([renderer->device supportsFamily:MTLGPUFamilyCommon2] ||
-                  [renderer->device supportsFamily:MTLGPUFamilyApple4])) {
+            if (@available(macOS 10.15, *)) {
+                if (!([renderer->device supportsFamily:MTLGPUFamilyCommon2] ||
+                      [renderer->device supportsFamily:MTLGPUFamilyApple4])) {
+                    return false;
+                }
+            } else {
                 return false;
             }
         }
@@ -3774,7 +3792,11 @@ static bool METAL_SupportsTextureFormat(
         case SDL_GPU_TEXTUREFORMAT_B5G6R5_UNORM:
         case SDL_GPU_TEXTUREFORMAT_B5G5R5A1_UNORM:
         case SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM:
-            return [renderer->device supportsFamily:MTLGPUFamilyApple1];
+                if (@available(macOS 10.15, *)) {
+                    return [renderer->device supportsFamily:MTLGPUFamilyApple1];
+                } else {
+                    return false;
+                }
 
         // Requires BC compression support
         case SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM:
diff --git a/src/hidapi/mac/hid.c b/src/hidapi/mac/hid.c
index db20b35c031c9..8acb6da7feb91 100644
--- a/src/hidapi/mac/hid.c
+++ b/src/hidapi/mac/hid.c
@@ -1572,7 +1572,7 @@ int HID_API_EXPORT_CALL hid_get_report_descriptor(hid_device *dev, unsigned char
 		}
 
 		memcpy(buf, descriptor_buf, copy_len);
-		return copy_len;
+		return (int)copy_len;
 	}
 	else {
 		register_device_error(dev, "Failed to get kIOHIDReportDescriptorKey property");
diff --git a/src/process/posix/SDL_posixprocess.c b/src/process/posix/SDL_posixprocess.c
index a3c3fb38781d3..ce0d58ce3b7bd 100644
--- a/src/process/posix/SDL_posixprocess.c
+++ b/src/process/posix/SDL_posixprocess.c
@@ -143,7 +143,7 @@ static bool AddFileDescriptorCloseActions(posix_spawn_file_actions_t *fa)
         }
         closedir(dir);
     } else {
-        for (int fd = sysconf(_SC_OPEN_MAX) - 1; fd > STDERR_FILENO; --fd) {
+        for (int fd = (int)(sysconf(_SC_OPEN_MAX) - 1); fd > STDERR_FILENO; --fd) {
             int flags = fcntl(fd, F_GETFD);
             if (flags < 0 || (flags & FD_CLOEXEC)) {
                 continue;
diff --git a/src/video/cocoa/SDL_cocoapen.m b/src/video/cocoa/SDL_cocoapen.m
index 663472beedbdc..6a9ff9a188266 100644
--- a/src/video/cocoa/SDL_cocoapen.m
+++ b/src/video/cocoa/SDL_cocoapen.m
@@ -115,7 +115,7 @@ static void Cocoa_HandlePenProximityEvent(SDL_CocoaWindowData *_data, NSEvent *e
 
 static void Cocoa_HandlePenPointEvent(SDL_CocoaWindowData *_data, NSEvent *event)
 {
-    const Uint32 timestamp = Cocoa_GetEventTimestamp([event timestamp]);
+    const Uint64 timestamp = Cocoa_GetEventTimestamp([event timestamp]);
     Cocoa_PenHandle *handle = Cocoa_FindPenByDeviceID([event deviceID], [event pointingDeviceID]);
     if (!handle) {
         return;
diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m
index 41f88236dba18..15efd37354b59 100644
--- a/src/video/uikit/SDL_uikitviewcontroller.m
+++ b/src/video/uikit/SDL_uikitviewcontroller.m
@@ -404,7 +404,7 @@ - (void)setKeyboardProperties:(SDL_PropertiesID) props
         break;
     case SDL_TEXTINPUT_TYPE_TEXT_USERNAME:
         textField.keyboardType = UIKeyboardTypeDefault;
-        if (@available(iOS 11.0, *)) {
+        if (@available(iOS 11.0, tvOS 11.0, *)) {
             textField.textContentType = UITextContentTypeUsername;
         } else {
             textField.textContentType = nil;
@@ -412,7 +412,7 @@ - (void)setKeyboardProperties:(SDL_PropertiesID) props
         break;
     case SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN:
         textField.keyboardType = UIKeyboardTypeDefault;
-        if (@available(iOS 11.0, *)) {
+        if (@available(iOS 11.0, tvOS 11.0, *)) {
             textField.textContentType = UITextContentTypePassword;
         } else {
             textField.textContentType = nil;
@@ -421,7 +421,7 @@ - (void)setKeyboardProperties:(SDL_PropertiesID) props
         break;
     case SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE:
         textField.keyboardType = UIKeyboardTypeDefault;
-        if (@available(iOS 11.0, *)) {
+        if (@available(iOS 11.0, tvOS 11.0, *)) {
             textField.textContentType = UITextContentTypePassword;
         } else {
             textField.textContentType = nil;
@@ -433,7 +433,7 @@ - (void)setKeyboardProperties:(SDL_PropertiesID) props
         break;
     case SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN:
         textField.keyboardType = UIKeyboardTypeNumberPad;
-        if (@available(iOS 12.0, *)) {
+        if (@available(iOS 12.0, tvOS 12.0, *)) {
             textField.textContentType = UITextContentTypeOneTimeCode;
         } else {
             textField.textContentType = nil;
@@ -442,7 +442,7 @@ - (void)setKeyboardProperties:(SDL_PropertiesID) props
         break;
     case SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE:
         textField.keyboardType = UIKeyboardTypeNumberPad;
-        if (@available(iOS 12.0, *)) {
+        if (@available(iOS 12.0, tvOS 12.0, *)) {
             textField.textContentType = UITextContentTypeOneTimeCode;
         } else {
             textField.textContentType = nil;