Enable high refresh rates on iOS
Fixes https://github.com/libsdl-org/SDL/issues/7518
This commit is contained in:
@@ -111,6 +111,19 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||||||
SDL_HideHomeIndicatorHintChanged,
|
SDL_HideHomeIndicatorHintChanged,
|
||||||
(__bridge void *)self);
|
(__bridge void *)self);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Enable high refresh rates on iOS
|
||||||
|
// To enable this on phones, you should add the following line to Info.plist:
|
||||||
|
// <key>CADisableMinimumFrameDurationOnPhone</key> <true/>
|
||||||
|
if (@available(iOS 15.0, tvOS 15.0, *)) {
|
||||||
|
const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
||||||
|
if (mode && mode->refresh_rate > 60.0f) {
|
||||||
|
int frame_rate = (int)mode->refresh_rate;
|
||||||
|
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
|
||||||
|
displayLink.preferredFrameRateRange = CAFrameRateRangeMake((frame_rate * 2) / 3, frame_rate, frame_rate);
|
||||||
|
[displayLink addToRunLoop:NSRunLoop.currentRunLoop forMode:NSDefaultRunLoopMode];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -145,6 +158,9 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||||||
{
|
{
|
||||||
[self stopAnimation];
|
[self stopAnimation];
|
||||||
|
|
||||||
|
if (interval <= 0) {
|
||||||
|
interval = 1;
|
||||||
|
}
|
||||||
animationInterval = interval;
|
animationInterval = interval;
|
||||||
animationCallback = callback;
|
animationCallback = callback;
|
||||||
animationCallbackParam = callbackParam;
|
animationCallbackParam = callbackParam;
|
||||||
@@ -185,7 +201,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
|||||||
- (void)doLoop:(CADisplayLink *)sender
|
- (void)doLoop:(CADisplayLink *)sender
|
||||||
{
|
{
|
||||||
// Don't run the game loop while a messagebox is up
|
// Don't run the game loop while a messagebox is up
|
||||||
if (!UIKit_ShowingMessageBox()) {
|
if (animationCallback && !UIKit_ShowingMessageBox()) {
|
||||||
// See the comment in the function definition.
|
// See the comment in the function definition.
|
||||||
#if defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2)
|
#if defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2)
|
||||||
UIKit_GL_RestoreCurrentContext();
|
UIKit_GL_RestoreCurrentContext();
|
||||||
|
|||||||
Reference in New Issue
Block a user