From 041c0b7c05bb8c57497a69578d91c01ca396da8b Mon Sep 17 00:00:00 2001 From: Ansariel Date: Sat, 9 Nov 2024 18:31:47 +0100 Subject: [PATCH] Optimize this... --- indra/newview/llstatusbar.cpp | 74 +++++++++++++++-------------------- 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/indra/newview/llstatusbar.cpp b/indra/newview/llstatusbar.cpp index 4b07a763f4..8288849701 100644 --- a/indra/newview/llstatusbar.cpp +++ b/indra/newview/llstatusbar.cpp @@ -306,9 +306,6 @@ bool LLStatusBar::postBuild() mBoxBalance = getChild("balance"); mBoxBalance->setClickedCallback( &LLStatusBar::onClickBalance, this ); - // show fpslimit reached in FPS status bar - getChild("FPSText")->setClickedCallback( std::bind(&LLUrlAction::executeSLURL, "secondlife:///app/openfloater/preferences?search=limit%20framerate", true)); - mIconPresetsCamera = getChild( "presets_icon_camera" ); //mIconPresetsCamera->setMouseEnterCallback(boost::bind(&LLStatusBar::mIconPresetsCamera, this)); if (gSavedSettings.getBOOL("FSStatusBarMenuButtonPopupOnRollover")) @@ -489,8 +486,9 @@ bool LLStatusBar::postBuild() mTimeMediaPanel = getChild("time_and_media_bg"); // Make FPS a clickable button with contextual colour - mFPSText = getChild("FPSText"); // mFPSText = getChild("FPSText"); + mFPSText = getChild("FPSText"); + mFPSText->setClickedCallback(std::bind(&LLUrlAction::executeSLURL, "secondlife:///app/openfloater/preferences?search=limit%20framerate", true)); // mVolumeIconsWidth = mBtnVolume->getRect().mRight - mStreamToggle->getRect().mLeft; @@ -606,60 +604,52 @@ void LLStatusBar::refresh() static LLCachedControl fsStatusBarShowFPS(gSavedSettings, "FSStatusBarShowFPS"); if (fsStatusBarShowFPS && mFPSUpdateTimer.getElapsedTimeF32() > 1.f) { - static LLCachedControl max_fps(gSavedSettings, "FramePerSecondLimit"); + static LLCachedControl max_fps(gSavedSettings, "FramePerSecondLimit"); static LLCachedControl limit_fps_enabled(gSavedSettings, "FSLimitFramerate"); static LLCachedControl vsync_enabled(gSavedSettings, "RenderVSyncEnable"); - const auto FPS_below_limit_color = LLUIColorTable::instance().getColor( "Yellow" ); - const auto FPS_limit_reached_color = LLUIColorTable::instance().getColor( "Green" ); - const auto vsync_limit_reached_color = LLUIColorTable::instance().getColor( "Green" ); - const auto FPS_uncapped_color = LLUIColorTable::instance().getColor( "White" ); - const auto FPS_unfocussed_color = LLUIColorTable::instance().getColor( "Gray" ); + static const auto fps_below_limit_color = LLUIColorTable::instance().getColor("Yellow"); + static const auto fps_limit_reached_color = LLUIColorTable::instance().getColor("Green"); + static const auto vsync_limit_reached_color = LLUIColorTable::instance().getColor("Green"); + static const auto fps_uncapped_color = LLUIColorTable::instance().getColor("White"); + static const auto fps_unfocussed_color = LLUIColorTable::instance().getColor("Gray"); + static auto current_fps_color = fps_uncapped_color; + mFPSUpdateTimer.reset(); - S32 vsync_freq=-1; - auto fps = LLTrace::get_frame_recording().getPeriodMedianPerSec(LLStatViewer::FPS); - if (gViewerWindow && gViewerWindow->getWindow()) - { - vsync_freq = gViewerWindow->getWindow()->getRefreshRate(); - } - mFPSText->setText(llformat("%.1f", fps )); + const auto fps = LLTrace::get_frame_recording().getPeriodMedianPerSec(LLStatViewer::FPS); + mFPSText->setText(llformat("%.1f", fps)); + // if background, go grey, else go white unless we have a cap (checked next) - auto fps_color = FPS_uncapped_color; - if ((gViewerWindow && !gViewerWindow->getWindow()->getVisible()) - || !gFocusMgr.getAppHasFocus()) + auto fps_color{ fps_uncapped_color }; + auto window = gViewerWindow ? gViewerWindow->getWindow() : nullptr; + if ((window && !window->getVisible()) || !gFocusMgr.getAppHasFocus()) { - fps_color = FPS_unfocussed_color; + fps_color = fps_unfocussed_color; } else { + S32 vsync_freq{ -1 }; + if (window) + { + vsync_freq = window->getRefreshRate(); + } + if (limit_fps_enabled && max_fps > 0) { - if (fps >= max_fps-1) // allow a small undershoot - { - fps_color = FPS_limit_reached_color; - } - else - { - fps_color = FPS_below_limit_color; - } + fps_color = (fps >= max_fps - 1) ? fps_limit_reached_color : fps_below_limit_color; } // use vsync if enabled and the freq is lower than the max_fps - if (vsync_enabled && vsync_freq > 0) + if (vsync_enabled && vsync_freq > 0 && (!limit_fps_enabled || vsync_freq < (S32)max_fps)) { - if ( !limit_fps_enabled || (limit_fps_enabled && vsync_freq < (S32)max_fps) ) - { - if (fps >= vsync_freq -1 ) - { - fps_color = vsync_limit_reached_color; - } - else - { - fps_color = FPS_below_limit_color; - } - } + fps_color = (fps >= vsync_freq - 1) ? vsync_limit_reached_color : fps_below_limit_color; } } - mFPSText->setColor(fps_color); + + if (current_fps_color != fps_color) + { + mFPSText->setColor(fps_color); + current_fps_color = fps_color; + } } //