Skip to content

Commit

Permalink
Merge pull request #16725 from hrydgard/windows-ui-refresh-rate
Browse files Browse the repository at this point in the history
Windows: Adjust window sleep interval in idle menus to refresh rate
  • Loading branch information
hrydgard committed Jan 5, 2023
2 parents 389c7bf + 14f45e3 commit 3bb2607
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ void KeepScreenAwake() {
}

void Core_RunLoop(GraphicsContext *ctx) {
float refreshRate = System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE);

graphicsContext = ctx;
while ((GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT) {
// In case it was pending, we're not in game anymore. We won't get to Core_Run().
Expand All @@ -232,7 +234,7 @@ void Core_RunLoop(GraphicsContext *ctx) {

// Simple throttling to not burn the GPU in the menu.
double diffTime = time_now_d() - startTime;
int sleepTime = (int)(1000.0 / 60.0) - (int)(diffTime * 1000.0);
int sleepTime = (int)(1000.0 / refreshRate) - (int)(diffTime * 1000.0);
if (sleepTime > 0)
sleep_ms(sleepTime);
if (!windowHidden) {
Expand Down
19 changes: 18 additions & 1 deletion Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,23 @@ static int ScreenDPI() {
#endif
#endif

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

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

int System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE:
Expand Down Expand Up @@ -311,7 +328,7 @@ int System_GetPropertyInt(SystemProperty prop) {
float System_GetPropertyFloat(SystemProperty prop) {
switch (prop) {
case SYSPROP_DISPLAY_REFRESH_RATE:
return 60.f;
return (float)ScreenRefreshRateHz();
case SYSPROP_DISPLAY_DPI:
return (float)ScreenDPI();
case SYSPROP_DISPLAY_SAFE_INSET_LEFT:
Expand Down

0 comments on commit 3bb2607

Please sign in to comment.