mirror of
https://github.com/azahar-emu/azahar
synced 2025-11-06 23:19:57 +01:00
Use MacOS-specific refresh rate check to avoid SDL race condition (#1262)
* Use MacOS-specific refresh rate check to avoid SDL race condition * IsLowRefreshRate: Change back to `SDL_Init` just to be safe
This commit is contained in:
parent
4b4d4f09da
commit
885bb71da8
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
namespace AppleUtils {
|
namespace AppleUtils {
|
||||||
|
|
||||||
|
float GetRefreshRate();
|
||||||
int IsLowPowerModeEnabled();
|
int IsLowPowerModeEnabled();
|
||||||
|
|
||||||
}
|
} // namespace AppleUtils
|
||||||
|
|||||||
@ -2,10 +2,29 @@
|
|||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <CoreGraphics/CoreGraphics.h>
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
namespace AppleUtils {
|
namespace AppleUtils {
|
||||||
|
|
||||||
|
float GetRefreshRate() { // TODO: How does this handle multi-monitor? -OS
|
||||||
|
NSScreen* screen = [NSScreen mainScreen];
|
||||||
|
if (screen) {
|
||||||
|
NSDictionary* screenInfo = [screen deviceDescription];
|
||||||
|
CGDirectDisplayID displayID =
|
||||||
|
(CGDirectDisplayID)[screenInfo[@"NSScreenNumber"] unsignedIntValue];
|
||||||
|
CGDisplayModeRef displayMode = CGDisplayCopyDisplayMode(displayID);
|
||||||
|
if (displayMode) {
|
||||||
|
CGFloat refreshRate = CGDisplayModeGetRefreshRate(displayMode);
|
||||||
|
CFRelease(displayMode);
|
||||||
|
return refreshRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 60; // Something went wrong, so just return a generic value
|
||||||
|
}
|
||||||
|
|
||||||
int IsLowPowerModeEnabled() {
|
int IsLowPowerModeEnabled() {
|
||||||
return (int)[NSProcessInfo processInfo].lowPowerModeEnabled;
|
return (int)[NSProcessInfo processInfo].lowPowerModeEnabled;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,11 @@ constexpr static std::array<vk::DescriptorSetLayoutBinding, 1> PRESENT_BINDINGS
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static bool IsLowRefreshRate() {
|
static bool IsLowRefreshRate() {
|
||||||
#ifdef ENABLE_SDL2
|
#if defined(__APPLE__) || defined(ENABLE_SDL2)
|
||||||
|
#ifdef __APPLE__ // Need a special implementation because MacOS kills itself in disgust if the
|
||||||
|
// input thread calls SDL_PumpEvents at the same time as we're in SDL_Init here.
|
||||||
|
const auto cur_refresh_rate = AppleUtils::GetRefreshRate();
|
||||||
|
#elif defined(ENABLE_SDL2)
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||||
LOG_ERROR(Render_Vulkan, "SDL video failed to initialize, unable to check refresh rate");
|
LOG_ERROR(Render_Vulkan, "SDL video failed to initialize, unable to check refresh rate");
|
||||||
return false;
|
return false;
|
||||||
@ -71,6 +75,7 @@ static bool IsLowRefreshRate() {
|
|||||||
const auto cur_refresh_rate = cur_display_mode.refresh_rate;
|
const auto cur_refresh_rate = cur_display_mode.refresh_rate;
|
||||||
|
|
||||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
if (cur_refresh_rate < SCREEN_REFRESH_RATE) {
|
if (cur_refresh_rate < SCREEN_REFRESH_RATE) {
|
||||||
LOG_WARNING(Render_Vulkan,
|
LOG_WARNING(Render_Vulkan,
|
||||||
@ -79,7 +84,7 @@ static bool IsLowRefreshRate() {
|
|||||||
cur_refresh_rate);
|
cur_refresh_rate);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif // defined(__APPLE__) || defined(ENABLE_SDL2)
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// Apple's low power mode sometimes limits applications to 30fps without changing the refresh
|
// Apple's low power mode sometimes limits applications to 30fps without changing the refresh
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user