SDL: ios: Move animation callback to its own typedef.

From 5416bd5fdc42ee78daa80136bc93095eb7af2bbb Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 12 Jun 2024 15:07:39 -0400
Subject: [PATCH] ios: Move animation callback to its own typedef.

---
 docs/README-ios.md                  |  2 +-
 include/SDL3/SDL_system.h           | 18 +++++++++++++++++-
 src/dynapi/SDL_dynapi_procs.h       |  2 +-
 src/dynapi/SDL_dynapi_unsupported.h |  4 ++++
 src/video/SDL_video_unsupported.c   |  5 +++--
 src/video/uikit/SDL_uikitwindow.m   |  2 +-
 6 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/docs/README-ios.md b/docs/README-ios.md
index 838d5f5b698be..d2838acf4f7ae 100644
--- a/docs/README-ios.md
+++ b/docs/README-ios.md
@@ -225,7 +225,7 @@ Game Center
 
 Game Center integration might require that you break up your main loop in order to yield control back to the system. In other words, instead of running an endless main loop, you run each frame in a callback function, using:
 
-    int SDL_iOSSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
+    int SDL_iOSSetAnimationCallback(SDL_Window * window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
 
 This will set up the given function to be called back on the animation callback, and then you have to return from main() to let the Cocoa event loop run.
 
diff --git a/include/SDL3/SDL_system.h b/include/SDL3/SDL_system.h
index f5bbb559ff69c..17db87032a58c 100644
--- a/include/SDL3/SDL_system.h
+++ b/include/SDL3/SDL_system.h
@@ -191,6 +191,22 @@ extern SDL_DECLSPEC int SDLCALL SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threa
  */
 #ifdef SDL_PLATFORM_IOS
 
+/**
+ * The prototype for an Apple iOS animation callback.
+ *
+ * This datatype is only useful on Apple iOS.
+ *
+ * After passing a function pointer of this type to SDL_iOSSetAnimationCallback,
+ * the system will call that function pointer at a regular interval.
+ *
+ * \param userdata what was passed as `callbackParam` to SDL_iOSSetAnimationCallback as `callbackParam`.
+ *
+ * \since This datatype is available since SDL 3.0.0.
+ *
+ * \sa SDL_iOSSetAnimationCallback
+ */
+typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
+
 /**
  * Use this function to set the animation callback on Apple iOS.
  *
@@ -228,7 +244,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threa
  *
  * \sa SDL_iOSSetEventPump
  */
-extern SDL_DECLSPEC int SDLCALL SDL_iOSSetAnimationCallback(SDL_Window * window, int interval, void (SDLCALL *callback)(void*), void *callbackParam);
+extern SDL_DECLSPEC int SDLCALL SDL_iOSSetAnimationCallback(SDL_Window * window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
 
 /**
  * Use this function to enable or disable the SDL event pump on Apple iOS.
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 40296ea975658..e695212a951a6 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -950,7 +950,7 @@ SDL_DYNAPI_PROC(int,SDL_hid_read_timeout,(SDL_hid_device *a, unsigned char *b, s
 SDL_DYNAPI_PROC(int,SDL_hid_send_feature_report,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return)
 SDL_DYNAPI_PROC(int,SDL_hid_set_nonblocking,(SDL_hid_device *a, int b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_hid_write,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return)
-SDL_DYNAPI_PROC(int,SDL_iOSSetAnimationCallback,(SDL_Window *a, int b, void (SDLCALL *c)(void*), void *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_iOSSetAnimationCallback,(SDL_Window *a, int b, SDL_iOSAnimationCallback c, void *d),(a,b,c,d),return)
 SDL_DYNAPI_PROC(void,SDL_iOSSetEventPump,(SDL_bool a),(a),)
 SDL_DYNAPI_PROC(size_t,SDL_iconv,(SDL_iconv_t a, const char **b, size_t *c, char **d, size_t *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(int,SDL_iconv_close,(SDL_iconv_t a),(a),return)
diff --git a/src/dynapi/SDL_dynapi_unsupported.h b/src/dynapi/SDL_dynapi_unsupported.h
index af6cd5f3ce5a7..272cd5e083fad 100644
--- a/src/dynapi/SDL_dynapi_unsupported.h
+++ b/src/dynapi/SDL_dynapi_unsupported.h
@@ -49,4 +49,8 @@ typedef struct XUserHandle XUserHandle;
 typedef void *SDL_AndroidRequestPermissionCallback;
 #endif
 
+#ifndef SDL_PLATFORM_IOS
+typedef void *SDL_iOSAnimationCallback;
+#endif
+
 #endif
diff --git a/src/video/SDL_video_unsupported.c b/src/video/SDL_video_unsupported.c
index 43bdc59856918..23a951f62e9b6 100644
--- a/src/video/SDL_video_unsupported.c
+++ b/src/video/SDL_video_unsupported.c
@@ -93,8 +93,9 @@ void SDL_OnApplicationDidChangeStatusBarOrientation(void)
 
 #ifndef SDL_VIDEO_DRIVER_UIKIT
 
-SDL_DECLSPEC int SDLCALL SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, void (*callback)(void *), void *callbackParam);
-int SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, void (*callback)(void *), void *callbackParam)
+typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
+SDL_DECLSPEC int SDLCALL SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
+int SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam)
 {
     (void)window;
     (void)interval;
diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m
index 452b90ca8a819..b443695d6bd19 100644
--- a/src/video/uikit/SDL_uikitwindow.m
+++ b/src/video/uikit/SDL_uikitwindow.m
@@ -449,7 +449,7 @@ void UIKit_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int
 }
 #endif /* !SDL_PLATFORM_TVOS */
 
-int SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, void (*callback)(void *), void *callbackParam)
+int SDL_iOSSetAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam)
 {
     if (!window || !window->driverdata) {
         return SDL_SetError("Invalid window");