Skip to content

Commit

Permalink
Enable high refresh rates on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 18, 2024
1 parent da80b9b commit 835b6e0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/video/uikit/SDL_uikitviewcontroller.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ - (instancetype)initWithSDLWindow:(SDL_Window *)_window
SDL_HideHomeIndicatorHintChanged,
(__bridge void *)self);
#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;
}
Expand Down Expand Up @@ -145,6 +158,9 @@ - (void)setAnimationCallback:(int)interval
{
[self stopAnimation];

if (interval <= 0) {
interval = 1;
}
animationInterval = interval;
animationCallback = callback;
animationCallbackParam = callbackParam;
Expand Down Expand Up @@ -185,7 +201,7 @@ - (void)stopAnimation
- (void)doLoop:(CADisplayLink *)sender
{
// 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.
#if defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2)
UIKit_GL_RestoreCurrentContext();
Expand Down

0 comments on commit 835b6e0

Please sign in to comment.