// // RefreshRateManager.h // interface/src/ // // Created by Dante Ruiz on 2019-04-15. // Copyright 2019 High Fidelity, Inc. // Copyright 2022-2023 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // SPDX-License-Identifier: Apache-2.0 // #ifndef hifi_RefreshRateManager_h #define hifi_RefreshRateManager_h #include #include #include #include #include #include #include #include class RefreshRateManager : QObject { Q_OBJECT public: enum RefreshRateProfile { ECO = 0, INTERACTIVE, REALTIME, PROFILE_NUM }; Q_ENUM(RefreshRateProfile) static bool isValidRefreshRateProfile(RefreshRateProfile value) { return (value >= RefreshRateProfile::ECO && value <= RefreshRateProfile::REALTIME); } /*@jsdoc *

Interface states that affect the refresh rate.

* * * * * * * * * * * * *
ValueNameDescription
0FOCUS_ACTIVEInterface has focus and the user is active or is in VR.
1FOCUS_INACTIVEInterface has focus and the user is inactive.
2UNFOCUSInterface doesn't have focus.
3MINIMIZEDInterface is minimized.
4STARTUPInterface is starting up.
5SHUTDOWNInterface is shutting down.
* @typedef {number} RefreshRateRegime */ enum RefreshRateRegime { FOCUS_ACTIVE = 0, FOCUS_INACTIVE, UNFOCUS, MINIMIZED, STARTUP, SHUTDOWN, REGIME_NUM }; Q_ENUM(RefreshRateRegime) static bool isValidRefreshRateRegime(RefreshRateRegime value) { return (value >= RefreshRateRegime::FOCUS_ACTIVE && value <= RefreshRateRegime::SHUTDOWN); } /*@jsdoc *

User experience (UX) modes.

* * * * * * * * *
ValueNameDescription
0DESKTOPDesktop user experience.
1VRVR use experience.
* @typedef {number} UXMode */ enum UXMode { DESKTOP = 0, VR, UX_NUM }; Q_ENUM(UXMode) static bool isValidUXMode(UXMode value) { return (value >= UXMode::DESKTOP && value <= UXMode::VR); } RefreshRateManager(); ~RefreshRateManager() = default; void setRefreshRateProfile(RefreshRateProfile refreshRateProfile); RefreshRateProfile getRefreshRateProfile() const; void setRefreshRateRegime(RefreshRateRegime refreshRateRegime); RefreshRateRegime getRefreshRateRegime() const; void setUXMode(UXMode uxMode); UXMode getUXMode() const { return _uxMode; } void setRefreshRateOperator(std::function refreshRateOperator) { _refreshRateOperator = refreshRateOperator; } int getActiveRefreshRate() const { return _activeRefreshRate; } void updateRefreshRateController() const; // query the refresh rate target at the specified combination int queryRefreshRateTarget(RefreshRateProfile profile, RefreshRateRegime regime, UXMode uxMode) const; void resetInactiveTimer(); void toggleInactive(); static std::string refreshRateProfileToString(RefreshRateProfile refreshRateProfile); static RefreshRateProfile refreshRateProfileFromString(std::string refreshRateProfile); static std::string uxModeToString(UXMode uxMode); static std::string refreshRateRegimeToString(RefreshRateRegime refreshRateRegime); private: mutable int _activeRefreshRate { 20 }; RefreshRateProfile _refreshRateProfile { RefreshRateProfile::INTERACTIVE}; RefreshRateRegime _refreshRateRegime { RefreshRateRegime::STARTUP }; UXMode _uxMode { UXMode::UX_NUM }; mutable ReadWriteLockable _refreshRateProfileSettingLock; Setting::Handle _refreshRateProfileSetting { "refreshRateProfile", RefreshRateProfile::INTERACTIVE }; std::function _refreshRateOperator { nullptr }; std::shared_ptr _inactiveTimer { std::make_shared() }; }; #endif