mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-09 03:29:43 -10:00
apple: better refresh rate restoration
This commit is contained in:
2 files changed
+53
-14
No files matched your search
@@ -457,6 +457,43 @@ static void *apple_display_server_init(void)
|
||||
RARCH_LOG("[Video] Stored original display mode for restoration\n");
|
||||
#endif
|
||||
|
||||
/* Sync the display link to the configured refresh rate.
|
||||
* The display link starts at the display's native rate before
|
||||
* config is parsed, so apply the user's setting now. */
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
if ( settings
|
||||
&& settings->floats.video_refresh_rate >= 10.0f
|
||||
&& settings->floats.video_refresh_rate <= 250.0f)
|
||||
{
|
||||
float hz = settings->floats.video_refresh_rate;
|
||||
CocoaView *view = [CocoaView get];
|
||||
#if defined(IOS)
|
||||
if (view && view.displayLink)
|
||||
{
|
||||
RARCH_DBG("[Video] Setting initial refresh rate to %.3f Hz\n", hz);
|
||||
#if (TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000) || (TARGET_OS_TV && __TV_OS_VERSION_MAX_ALLOWED >= 150000)
|
||||
if (@available(iOS 15, tvOS 15, *))
|
||||
view.displayLink.preferredFrameRateRange =
|
||||
CAFrameRateRangeMake(hz * 0.9, hz * 1.2, hz);
|
||||
else
|
||||
#endif
|
||||
view.displayLink.preferredFramesPerSecond = hz;
|
||||
}
|
||||
#elif defined(OSX) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000
|
||||
if (view)
|
||||
{
|
||||
if (@available(macOS 14, *))
|
||||
{
|
||||
RARCH_DBG("[Video] Setting initial refresh rate to %.3f Hz\n", hz);
|
||||
view.displayLink.preferredFrameRateRange =
|
||||
CAFrameRateRangeMake(hz * 0.9, hz * 1.2, hz);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return apple;
|
||||
}
|
||||
|
||||
|
||||
@@ -205,28 +205,30 @@ void rarch_stop_draw_observer(void)
|
||||
nsview_set_ptr(view);
|
||||
#if defined(IOS)
|
||||
view.displayLink = [CADisplayLink displayLinkWithTarget:view selector:@selector(step:)];
|
||||
{
|
||||
float hz = (float)[UIScreen mainScreen].maximumFramesPerSecond;
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 || __TV_OS_VERSION_MAX_ALLOWED >= 150000
|
||||
if (@available(iOS 15.0, tvOS 15.0, *))
|
||||
{
|
||||
/* Use a wide range by default to support ProMotion displays,
|
||||
* the display server will set the exact rate when needed */
|
||||
[view.displayLink setPreferredFrameRateRange:CAFrameRateRangeMake(60, 120, 120)];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* iOS 9-14: Use preferredFramesPerSecond as fallback */
|
||||
view.displayLink.preferredFramesPerSecond = 120;
|
||||
}
|
||||
if (@available(iOS 15.0, tvOS 15.0, *))
|
||||
[view.displayLink setPreferredFrameRateRange:
|
||||
CAFrameRateRangeMake(hz * 0.9, hz * 1.2, hz)];
|
||||
else
|
||||
view.displayLink.preferredFramesPerSecond = hz;
|
||||
#else
|
||||
/* Building with SDK < iOS 15: Use preferredFramesPerSecond */
|
||||
view.displayLink.preferredFramesPerSecond = 120;
|
||||
view.displayLink.preferredFramesPerSecond = hz;
|
||||
#endif
|
||||
}
|
||||
[view.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
|
||||
#elif defined(OSX) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000
|
||||
if (@available(macOS 14.0, *))
|
||||
{
|
||||
CGDirectDisplayID did = CGMainDisplayID();
|
||||
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(did);
|
||||
float hz = (float)CGDisplayModeGetRefreshRate(mode);
|
||||
CGDisplayModeRelease(mode);
|
||||
if (hz <= 0.0f)
|
||||
hz = 60.0f;
|
||||
view.displayLink = [view displayLinkWithTarget:view selector:@selector(step:)];
|
||||
view.displayLink.preferredFrameRateRange = CAFrameRateRangeMake(60, 120, 120);
|
||||
view.displayLink.preferredFrameRateRange = CAFrameRateRangeMake(hz * 0.9, hz * 1.2, hz);
|
||||
[view.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user