diff --git a/Common/TimeUtil.cpp b/Common/TimeUtil.cpp index 71800658d9..c246f011c4 100644 --- a/Common/TimeUtil.cpp +++ b/Common/TimeUtil.cpp @@ -256,6 +256,9 @@ double Instant::ElapsedSeconds() const { #define SLEEP_LOG_ENABLED 0 void sleep_ms(int ms, const char *reason) { + if (ms <= 0) { + return; + } #if SLEEP_LOG_ENABLED INFO_LOG(Log::System, "Sleep %d ms: %s", ms, reason); #endif @@ -271,6 +274,9 @@ void sleep_ms(int ms, const char *reason) { } void sleep_us(int us, const char *reason) { + if (us <= 0) { + return; + } #if SLEEP_LOG_ENABLED INFO_LOG(Log::System, "Sleep %d us: %s", us, reason); #endif diff --git a/Common/UI/View.h b/Common/UI/View.h index 97e5d77be6..f617773491 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -817,8 +817,6 @@ public: private: std::string text_; std::string rightText_; - - bool choiceStyle_ = false; }; class AbstractChoiceWithValueDisplay : public Choice { @@ -1094,7 +1092,7 @@ public: private: std::string text_; ImageID atlasImage_; - ImageSizeMode sizeMode_; + ImageSizeMode sizeMode_; // TODO: Not actually used yet. float scale_ = 1.0f; }; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index bf6ea41af6..ccbb3460ca 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1248,12 +1248,27 @@ void NativeFrame(GraphicsContext *graphicsContext) { g_BackgroundAudio.Play(); float refreshRate = System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE); - // Simple throttling to not burn the GPU in the menu. - // TODO: This is only necessary in MAILBOX or IMMEDIATE presentation modes. - double diffTime = time_now_d() - startTime; - int sleepTimeUs = (int)(1000000 * ((1.0 / refreshRate) - diffTime)); - if (sleepTimeUs > 0) - sleep_us(sleepTimeUs, "fallback-throttle"); + static double lastTime = 0.0; + if (lastTime > 0.0) { + double now = time_now_d(); + // Simple throttling to not burn the GPU in the menu. + // TODO: This should move into NativeFrame. + double diffTime = now - lastTime; + int sleepTimeUs = (int)(1000000 * ((1.0 / refreshRate) - diffTime)); + // printf("sleep: %0.3f ms (diff: %0.3f) %f\n", (double)sleepTimeUs / 1000, diffTime * 1000.0, refreshRate); + + // If presentation mode is FIFO, we don't need to sleep a lot, we'll be throttled by + // presentation. But still, let's sleep a bit. + // Actually, for some reason this increases latency a lot, to the degree that the UI + // gets hard to use.. Commenting out for now. + // if (g_frameTiming.PresentMode() == Draw::PresentMode::FIFO) { + // sleepTimeUs = std::min(2000, sleepTimeUs); // 2 ms + // } + + if (sleepTimeUs > 0) + sleep_us(sleepTimeUs, "fallback-throttle"); + } + lastTime = time_now_d(); } }