From ae0c1e88c35b51a7598eb0fd504d17cdf039c05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 4 Oct 2023 16:57:06 +0200 Subject: [PATCH] Move the menu frame-rate throttling to NativeFrame Now needed on Android since we added the ability to turn off vsync, which caused the menu to burn battery by rendering too fast. --- Core/Core.cpp | 17 ----------------- UI/NativeApp.cpp | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index f6b6dc422ef8..36f9fd0f83fd 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -212,24 +212,7 @@ void Core_RunLoop(GraphicsContext *ctx) { return; } - bool menuThrottle = (GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT; - - double startTime; - if (menuThrottle) { - startTime = time_now_d(); - } - 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; - int sleepTime = (int)(1000.0 / refreshRate) - (int)(diffTime * 1000.0); - if (sleepTime > 0) - sleep_ms(sleepTime); - } } void Core_DoSingleStep() { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 730e5cda8071..43deae061f6d 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1070,6 +1070,13 @@ static Matrix4x4 ComputeOrthoMatrix(float xres, float yres) { void NativeFrame(GraphicsContext *graphicsContext) { PROFILE_END_FRAME(); + bool menuThrottle = (GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT; + + double startTime; + if (menuThrottle) { + startTime = time_now_d(); + } + std::vector toProcess; { std::lock_guard lock(pendingMutex); @@ -1184,6 +1191,16 @@ void NativeFrame(GraphicsContext *graphicsContext) { // INFO_LOG(G3D, "Polling graphics context"); graphicsContext->Poll(); } + + 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; + int sleepTime = (int)(1000.0 / refreshRate) - (int)(diffTime * 1000.0); + if (sleepTime > 0) + sleep_ms(sleepTime); + } } bool HandleGlobalMessage(UIMessage message, const std::string &value) {