From 01050d4ed11389a0b92ba53da5501da014298f89 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 15 Jul 2017 17:41:58 -0300 Subject: [PATCH] iOS: Use modern replacements for deprecated functions, when available. --- src/video/SDL_sysvideo.h | 12 ++++++------ src/video/SDL_video.c | 12 ++++++------ src/video/uikit/SDL_uikitappdelegate.m | 11 ++++++----- src/video/uikit/SDL_uikitmodes.m | 5 ++--- src/video/uikit/SDL_uikitviewcontroller.m | 19 ++++++++++++++++++- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 94ba28558ab63..d1f5658c4cec0 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -419,12 +419,12 @@ extern SDL_bool SDL_ShouldAllowTopmost(void); extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches); -extern void SDL_OnApplicationWillTerminate(); -extern void SDL_OnApplicationDidReceiveMemoryWarning(); -extern void SDL_OnApplicationWillResignActive(); -extern void SDL_OnApplicationDidEnterBackground(); -extern void SDL_OnApplicationWillEnterForeground(); -extern void SDL_OnApplicationDidBecomeActive(); +extern void SDL_OnApplicationWillTerminate(void); +extern void SDL_OnApplicationDidReceiveMemoryWarning(void); +extern void SDL_OnApplicationWillResignActive(void); +extern void SDL_OnApplicationDidEnterBackground(void); +extern void SDL_OnApplicationWillEnterForeground(void); +extern void SDL_OnApplicationDidBecomeActive(void); #endif /* SDL_sysvideo_h_ */ diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 7b1bffdce7b0d..ab3a8efb57654 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -3863,17 +3863,17 @@ SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches) /* * Functions used by iOS application delegates */ -void SDL_OnApplicationWillTerminate() +void SDL_OnApplicationWillTerminate(void) { SDL_SendAppEvent(SDL_APP_TERMINATING); } -void SDL_OnApplicationDidReceiveMemoryWarning() +void SDL_OnApplicationDidReceiveMemoryWarning(void) { SDL_SendAppEvent(SDL_APP_LOWMEMORY); } -void SDL_OnApplicationWillResignActive() +void SDL_OnApplicationWillResignActive(void) { if (_this) { SDL_Window *window; @@ -3885,17 +3885,17 @@ void SDL_OnApplicationWillResignActive() SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND); } -void SDL_OnApplicationDidEnterBackground() +void SDL_OnApplicationDidEnterBackground(void) { SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND); } -void SDL_OnApplicationWillEnterForeground() +void SDL_OnApplicationWillEnterForeground(void) { SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND); } -void SDL_OnApplicationDidBecomeActive() +void SDL_OnApplicationDidBecomeActive(void) { SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND); diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m index 17dc4d9ab7045..b2badaa0280e5 100644 --- a/src/video/uikit/SDL_uikitappdelegate.m +++ b/src/video/uikit/SDL_uikitappdelegate.m @@ -513,23 +513,24 @@ - (void)sendDropFileForURL:(NSURL *)url SDL_SendDropComplete(NULL); } -#if TARGET_OS_TV -/* TODO: Use this on iOS 9+ as well? */ +#if TARGET_OS_TV || (defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0) + - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { /* TODO: Handle options */ [self sendDropFileForURL:url]; return YES; } -#endif /* TARGET_OS_TV */ -#if !TARGET_OS_TV +#else + - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { [self sendDropFileForURL:url]; return YES; } -#endif /* !TARGET_OS_TV */ + +#endif @end diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m index 12a4083a46b00..0798166c49913 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -273,6 +273,7 @@ @implementation SDL_DisplayModeData @autoreleasepool { int displayIndex = (int) (display - _this->displays); SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata; + CGRect frame = data.uiscreen.bounds; /* the default function iterates displays to make a fake offset, as if all the displays were side-by-side, which is fine for iOS. */ @@ -280,9 +281,7 @@ @implementation SDL_DisplayModeData return -1; } - CGRect frame = data.uiscreen.bounds; - -#if !TARGET_OS_TV +#if !TARGET_OS_TV && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 if (!UIKit_IsSystemVersionAtLeast(7.0)) { frame = [data.uiscreen applicationFrame]; } diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m index a8e36ef76e706..a4be1ed261634 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.m +++ b/src/video/uikit/SDL_uikitviewcontroller.m @@ -114,7 +114,22 @@ - (void)setAnimationCallback:(int)interval - (void)startAnimation { displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)]; - [displayLink setFrameInterval:animationInterval]; + +#ifdef __IPHONE_10_3 + SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata; + + if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)] + && data != nil && data.uiwindow != nil + && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) { + displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval; + } else +#endif + { +#if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300 + [displayLink setFrameInterval:animationInterval]; +#endif + } + [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } @@ -155,10 +170,12 @@ - (NSUInteger)supportedInterfaceOrientations return UIKit_GetSupportedOrientations(window); } +#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient { return ([self supportedInterfaceOrientations] & (1 << orient)) != 0; } +#endif - (BOOL)prefersStatusBarHidden {