Skip to content

Commit

Permalink
Merge pull request #18291 from hrydgard/cache-refresh-rate
Browse files Browse the repository at this point in the history
Reduce refresh rate checks on Windows
  • Loading branch information
hrydgard committed Oct 3, 2023
2 parents bd760b9 + e39980f commit 6a2e5dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
3 changes: 1 addition & 2 deletions Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ void UpdateRunLoop(GraphicsContext *ctx) {

// Note: not used on Android.
void Core_RunLoop(GraphicsContext *ctx) {
float refreshRate = System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE);

if (windowHidden && g_Config.bPauseWhenMinimized) {
sleep_ms(16);
return;
Expand All @@ -224,6 +222,7 @@ void Core_RunLoop(GraphicsContext *ctx) {
NativeFrame(ctx);

if (menuThrottle) {
float refreshRate = System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE);
// Simple throttling to not burn the GPU in the menu.
// TODO: This should move into NativeFrame. Also, it's only necessary in MAILBOX or IMMEDIATE presentation modes.
double diffTime = time_now_d() - startTime;
Expand Down
32 changes: 19 additions & 13 deletions Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,28 @@ static int ScreenDPI() {
#endif

static int ScreenRefreshRateHz() {
DEVMODE lpDevMode;
memset(&lpDevMode, 0, sizeof(DEVMODE));
lpDevMode.dmSize = sizeof(DEVMODE);
lpDevMode.dmDriverExtra = 0;

// TODO: Use QueryDisplayConfig instead (Win7+) so we can get fractional refresh rates correctly.

if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &lpDevMode) == 0) {
return 60; // default value
} else {
if (lpDevMode.dmFields & DM_DISPLAYFREQUENCY) {
return lpDevMode.dmDisplayFrequency > 60 ? lpDevMode.dmDisplayFrequency : 60;
static int rate = 0;
static double lastCheck = 0.0;
double now = time_now_d();
if (!rate || lastCheck < now - 10.0) {
lastCheck = now;
DEVMODE lpDevMode{};
lpDevMode.dmSize = sizeof(DEVMODE);
lpDevMode.dmDriverExtra = 0;

// TODO: Use QueryDisplayConfig instead (Win7+) so we can get fractional refresh rates correctly.

if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &lpDevMode) == 0) {
rate = 60; // default value
} else {
return 60;
if (lpDevMode.dmFields & DM_DISPLAYFREQUENCY) {
rate = lpDevMode.dmDisplayFrequency > 60 ? lpDevMode.dmDisplayFrequency : 60;
} else {
rate = 60;
}
}
}
return rate;
}

int System_GetPropertyInt(SystemProperty prop) {
Expand Down

0 comments on commit 6a2e5dd

Please sign in to comment.