mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge pull request #899 from HifiExperiments/refresh-rate
Custom refresh rate profile
This commit is contained in:
commit
b22f5fe4fe
6 changed files with 254 additions and 17 deletions
|
@ -347,6 +347,10 @@ Flickable {
|
|||
text: "Real-Time"
|
||||
refreshRatePreset: 2 // RefreshRateProfile::REALTIME
|
||||
}
|
||||
ListElement {
|
||||
text: "Custom"
|
||||
refreshRatePreset: 3 // RefreshRateProfile::CUSTOM
|
||||
}
|
||||
}
|
||||
|
||||
HifiControlsUit.ComboBox {
|
||||
|
@ -362,13 +366,7 @@ Flickable {
|
|||
currentIndex: -1
|
||||
|
||||
function refreshRefreshRateDropdownDisplay() {
|
||||
if (Performance.getRefreshRateProfile() === 0) {
|
||||
refreshRateDropdown.currentIndex = 0;
|
||||
} else if (Performance.getRefreshRateProfile() === 1) {
|
||||
refreshRateDropdown.currentIndex = 1;
|
||||
} else {
|
||||
refreshRateDropdown.currentIndex = 2;
|
||||
}
|
||||
refreshRateDropdown.currentIndex = Performance.getRefreshRateProfile();
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
|
@ -382,6 +380,180 @@ Flickable {
|
|||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
Layout.topMargin: 32
|
||||
visible: refreshRateDropdown.currentIndex == 3
|
||||
|
||||
RowLayout {
|
||||
Layout.margins: 8
|
||||
|
||||
HifiControlsUit.SpinBox {
|
||||
id: refreshRateCustomFocusActive
|
||||
decimals: 0
|
||||
width: 160
|
||||
height: 32
|
||||
suffix: " FPS"
|
||||
label: "Focus Active"
|
||||
realFrom: 1
|
||||
realTo: 1000
|
||||
realStepSize: 15
|
||||
realValue: 60
|
||||
colorScheme: hifi.colorSchemes.dark
|
||||
property var loaded: false
|
||||
|
||||
Component.onCompleted: {
|
||||
realValue = Performance.getCustomRefreshRate(0)
|
||||
loaded = true
|
||||
}
|
||||
|
||||
onRealValueChanged: {
|
||||
if (loaded) {
|
||||
Performance.setCustomRefreshRate(0, realValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HifiControlsUit.SpinBox {
|
||||
id: refreshRateCustomFocusInactive
|
||||
decimals: 0
|
||||
width: 160
|
||||
height: 32
|
||||
suffix: " FPS"
|
||||
label: "Focus Inactive"
|
||||
realFrom: 1
|
||||
realTo: 1000
|
||||
realStepSize: 15
|
||||
realValue: 60
|
||||
colorScheme: hifi.colorSchemes.dark
|
||||
property var loaded: false
|
||||
|
||||
Component.onCompleted: {
|
||||
realValue = Performance.getCustomRefreshRate(1)
|
||||
loaded = true
|
||||
}
|
||||
|
||||
onRealValueChanged: {
|
||||
if (loaded) {
|
||||
Performance.setCustomRefreshRate(1, realValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.margins: 8
|
||||
|
||||
HifiControlsUit.SpinBox {
|
||||
id: refreshRateCustomUnfocus
|
||||
decimals: 0
|
||||
width: 160
|
||||
height: 32
|
||||
suffix: " FPS"
|
||||
label: "Unfocus"
|
||||
realFrom: 1
|
||||
realTo: 1000
|
||||
realStepSize: 15
|
||||
realValue: 60
|
||||
colorScheme: hifi.colorSchemes.dark
|
||||
property var loaded: false
|
||||
|
||||
Component.onCompleted: {
|
||||
realValue = Performance.getCustomRefreshRate(2)
|
||||
loaded = true
|
||||
}
|
||||
|
||||
onRealValueChanged: {
|
||||
if (loaded) {
|
||||
Performance.setCustomRefreshRate(2, realValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HifiControlsUit.SpinBox {
|
||||
id: refreshRateCustomMinimized
|
||||
decimals: 0
|
||||
width: 160
|
||||
height: 32
|
||||
suffix: " FPS"
|
||||
label: "Minimized"
|
||||
realFrom: 1
|
||||
realTo: 1000
|
||||
realStepSize: 1
|
||||
realValue: 60
|
||||
colorScheme: hifi.colorSchemes.dark
|
||||
property var loaded: false
|
||||
|
||||
Component.onCompleted: {
|
||||
realValue = Performance.getCustomRefreshRate(3)
|
||||
loaded = true
|
||||
}
|
||||
|
||||
onRealValueChanged: {
|
||||
if (loaded) {
|
||||
Performance.setCustomRefreshRate(3, realValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.margins: 8
|
||||
|
||||
HifiControlsUit.SpinBox {
|
||||
id: refreshRateCustomStartup
|
||||
decimals: 0
|
||||
width: 160
|
||||
height: 32
|
||||
suffix: " FPS"
|
||||
label: "Startup"
|
||||
realFrom: 1
|
||||
realTo: 1000
|
||||
realStepSize: 15
|
||||
realValue: 60
|
||||
colorScheme: hifi.colorSchemes.dark
|
||||
property var loaded: false
|
||||
|
||||
Component.onCompleted: {
|
||||
realValue = Performance.getCustomRefreshRate(4)
|
||||
loaded = true
|
||||
}
|
||||
|
||||
onRealValueChanged: {
|
||||
if (loaded) {
|
||||
Performance.setCustomRefreshRate(4, realValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HifiControlsUit.SpinBox {
|
||||
id: refreshRateCustomShutdown
|
||||
decimals: 0
|
||||
width: 160
|
||||
height: 32
|
||||
suffix: " FPS"
|
||||
label: "Shutdown"
|
||||
realFrom: 1
|
||||
realTo: 1000
|
||||
realStepSize: 15
|
||||
realValue: 60
|
||||
colorScheme: hifi.colorSchemes.dark
|
||||
property var loaded: false
|
||||
|
||||
Component.onCompleted: {
|
||||
realValue = Performance.getCustomRefreshRate(5)
|
||||
loaded = true
|
||||
}
|
||||
|
||||
onRealValueChanged: {
|
||||
if (loaded) {
|
||||
Performance.setCustomRefreshRate(5, realValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.preferredWidth: parent.width
|
||||
Layout.preferredHeight: 35
|
||||
|
|
|
@ -48,12 +48,13 @@ static const int VR_TARGET_RATE = 90;
|
|||
* <tr><td><code>"Interactive"</code></td><td>Medium refresh rate, which is reduced when Interface doesn't have focus or is
|
||||
* minimized.</td></tr>
|
||||
* <tr><td><code>"Realtime"</code></td><td>High refresh rate, even when Interface doesn't have focus or is minimized.
|
||||
* <tr><td><code>"Custom"</code></td><td>Custom refresh rate for full control over the refresh rate in all states.
|
||||
* </tbody>
|
||||
* </table>
|
||||
* @typedef {string} RefreshRateProfileName
|
||||
*/
|
||||
static const std::array<std::string, RefreshRateManager::RefreshRateProfile::PROFILE_NUM> REFRESH_RATE_PROFILE_TO_STRING =
|
||||
{ { "Eco", "Interactive", "Realtime" } };
|
||||
{ { "Eco", "Interactive", "Realtime", "Custom" } };
|
||||
|
||||
/*@jsdoc
|
||||
* <p>Interface states that affect the refresh rate.</p>
|
||||
|
@ -94,7 +95,8 @@ static const std::array<std::string, RefreshRateManager::UXMode::UX_NUM> UX_MODE
|
|||
static const std::map<std::string, RefreshRateManager::RefreshRateProfile> REFRESH_RATE_PROFILE_FROM_STRING =
|
||||
{ { "Eco", RefreshRateManager::RefreshRateProfile::ECO },
|
||||
{ "Interactive", RefreshRateManager::RefreshRateProfile::INTERACTIVE },
|
||||
{ "Realtime", RefreshRateManager::RefreshRateProfile::REALTIME } };
|
||||
{ "Realtime", RefreshRateManager::RefreshRateProfile::REALTIME },
|
||||
{ "Custom", RefreshRateManager::RefreshRateProfile::CUSTOM } };
|
||||
|
||||
|
||||
// Porfile regimes are:
|
||||
|
@ -107,10 +109,12 @@ static const std::array<int, RefreshRateManager::RefreshRateRegime::REGIME_NUM>
|
|||
{ { 30, 20, 10, 2, 30, 30 } };
|
||||
|
||||
static const std::array<int, RefreshRateManager::RefreshRateRegime::REGIME_NUM> REALTIME_PROFILE =
|
||||
{ { 60, 60, 60, 2, 30, 30} };
|
||||
{ { 60, 60, 60, 2, 30, 30 } };
|
||||
|
||||
static const std::array<std::array<int, RefreshRateManager::RefreshRateRegime::REGIME_NUM>, RefreshRateManager::RefreshRateProfile::PROFILE_NUM> REFRESH_RATE_PROFILES =
|
||||
{ { ECO_PROFILE, INTERACTIVE_PROFILE, REALTIME_PROFILE } };
|
||||
static const std::array<int, RefreshRateManager::RefreshRateRegime::REGIME_NUM> CUSTOM_PROFILE = REALTIME_PROFILE; // derived from settings and modified by scripts below
|
||||
|
||||
static std::array<std::array<int, RefreshRateManager::RefreshRateRegime::REGIME_NUM>, RefreshRateManager::RefreshRateProfile::PROFILE_NUM> REFRESH_RATE_PROFILES =
|
||||
{ { ECO_PROFILE, INTERACTIVE_PROFILE, REALTIME_PROFILE, CUSTOM_PROFILE } };
|
||||
|
||||
|
||||
static const int INACTIVE_TIMER_LIMIT = 3000;
|
||||
|
@ -134,6 +138,10 @@ std::string RefreshRateManager::uxModeToString(RefreshRateManager::RefreshRateMa
|
|||
|
||||
RefreshRateManager::RefreshRateManager() {
|
||||
_refreshRateProfile = (RefreshRateManager::RefreshRateProfile) _refreshRateProfileSetting.get();
|
||||
for (size_t i = 0; i < _customRefreshRateSettings.size(); i++) {
|
||||
REFRESH_RATE_PROFILES[CUSTOM][i] = _customRefreshRateSettings[i].get();
|
||||
}
|
||||
|
||||
_inactiveTimer->setInterval(INACTIVE_TIMER_LIMIT);
|
||||
_inactiveTimer->setSingleShot(true);
|
||||
QObject::connect(_inactiveTimer.get(), &QTimer::timeout, [&] {
|
||||
|
@ -168,6 +176,25 @@ void RefreshRateManager::setRefreshRateProfile(RefreshRateManager::RefreshRatePr
|
|||
}
|
||||
}
|
||||
|
||||
int RefreshRateManager::getCustomRefreshRate(RefreshRateRegime regime) {
|
||||
if (isValidRefreshRateRegime(regime)) {
|
||||
return REFRESH_RATE_PROFILES[RefreshRateProfile::CUSTOM][regime];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RefreshRateManager::setCustomRefreshRate(RefreshRateRegime regime, int value) {
|
||||
value = std::max(value, 1);
|
||||
if (isValidRefreshRateRegime(regime)) {
|
||||
_refreshRateProfileSettingLock.withWriteLock([&] {
|
||||
REFRESH_RATE_PROFILES[RefreshRateProfile::CUSTOM][regime] = value;
|
||||
_customRefreshRateSettings[regime].set(value);
|
||||
});
|
||||
updateRefreshRateController();
|
||||
}
|
||||
}
|
||||
|
||||
RefreshRateManager::RefreshRateProfile RefreshRateManager::getRefreshRateProfile() const {
|
||||
RefreshRateManager::RefreshRateProfile profile = RefreshRateManager::RefreshRateProfile::REALTIME;
|
||||
|
||||
|
@ -191,7 +218,6 @@ void RefreshRateManager::setRefreshRateRegime(RefreshRateManager::RefreshRateReg
|
|||
_refreshRateRegime = refreshRateRegime;
|
||||
updateRefreshRateController();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RefreshRateManager::setUXMode(RefreshRateManager::UXMode uxMode) {
|
||||
|
|
|
@ -32,10 +32,11 @@ public:
|
|||
ECO = 0,
|
||||
INTERACTIVE,
|
||||
REALTIME,
|
||||
CUSTOM,
|
||||
PROFILE_NUM
|
||||
};
|
||||
Q_ENUM(RefreshRateProfile)
|
||||
static bool isValidRefreshRateProfile(RefreshRateProfile value) { return (value >= RefreshRateProfile::ECO && value <= RefreshRateProfile::REALTIME); }
|
||||
static bool isValidRefreshRateProfile(RefreshRateProfile value) { return (value >= 0 && value < RefreshRateProfile::PROFILE_NUM); }
|
||||
|
||||
/*@jsdoc
|
||||
* <p>Interface states that affect the refresh rate.</p>
|
||||
|
@ -106,6 +107,9 @@ public:
|
|||
// query the refresh rate target at the specified combination
|
||||
int queryRefreshRateTarget(RefreshRateProfile profile, RefreshRateRegime regime, UXMode uxMode) const;
|
||||
|
||||
int getCustomRefreshRate(RefreshRateRegime regime);
|
||||
void setCustomRefreshRate(RefreshRateRegime regime, int value);
|
||||
|
||||
void resetInactiveTimer();
|
||||
void toggleInactive();
|
||||
|
||||
|
@ -121,7 +125,15 @@ private:
|
|||
UXMode _uxMode { UXMode::DESKTOP };
|
||||
|
||||
mutable ReadWriteLockable _refreshRateProfileSettingLock;
|
||||
Setting::Handle<int> _refreshRateProfileSetting { "refreshRateProfile", RefreshRateProfile::INTERACTIVE };
|
||||
Setting::Handle<int> _refreshRateProfileSetting{ "refreshRateProfile", RefreshRateProfile::INTERACTIVE };
|
||||
std::array<Setting::Handle<int>, REGIME_NUM> _customRefreshRateSettings { {
|
||||
{ "customRefreshRateFocusActive", 60 },
|
||||
{ "customRefreshRateFocusInactive", 60 },
|
||||
{ "customRefreshRateUnfocus", 60 },
|
||||
{ "customRefreshRateMinimized", 2 },
|
||||
{ "customRefreshRateStartup", 30 },
|
||||
{ "customRefreshRateShutdown", 30 }
|
||||
} };
|
||||
|
||||
std::function<void(int)> _refreshRateOperator { nullptr };
|
||||
|
||||
|
|
|
@ -56,12 +56,22 @@ void PerformanceScriptingInterface::setRefreshRateProfile(RefreshRateProfile ref
|
|||
emit settingsChanged();
|
||||
}
|
||||
|
||||
void PerformanceScriptingInterface::setCustomRefreshRate(RefreshRateManager::RefreshRateRegime refreshRateRegime, int value)
|
||||
{
|
||||
qApp->getRefreshRateManager().setCustomRefreshRate(refreshRateRegime, value);
|
||||
emit settingsChanged();
|
||||
}
|
||||
|
||||
int PerformanceScriptingInterface::getCustomRefreshRate(RefreshRateManager::RefreshRateRegime refreshRateRegime) const {
|
||||
return qApp->getRefreshRateManager().getCustomRefreshRate(refreshRateRegime);
|
||||
}
|
||||
|
||||
PerformanceScriptingInterface::RefreshRateProfile PerformanceScriptingInterface::getRefreshRateProfile() const {
|
||||
return (PerformanceScriptingInterface::RefreshRateProfile)qApp->getRefreshRateManager().getRefreshRateProfile();
|
||||
}
|
||||
|
||||
QStringList PerformanceScriptingInterface::getRefreshRateProfileNames() const {
|
||||
static const QStringList refreshRateProfileNames = { "ECO", "INTERACTIVE", "REALTIME" };
|
||||
static const QStringList refreshRateProfileNames = { "ECO", "INTERACTIVE", "REALTIME", "CUSTOM" };
|
||||
return refreshRateProfileNames;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,6 +127,22 @@ public slots:
|
|||
*/
|
||||
void setRefreshRateProfile(RefreshRateProfile refreshRateProfile);
|
||||
|
||||
/*@jsdoc
|
||||
* Sets a custom refresh rate.
|
||||
* @function Performance.setCustomRefreshRate
|
||||
* @param {RefreshRateRegime} refreshRateRegime - The refresh rate regime
|
||||
* @param {int} value - The value for the regime
|
||||
*/
|
||||
void setCustomRefreshRate(RefreshRateManager::RefreshRateRegime refreshRateRegime, int value);
|
||||
|
||||
/*@jsdoc
|
||||
* Gets the value for a specific RefreshRateRegime.
|
||||
* @function Performance.getCustomRefreshRate
|
||||
* @param {RefreshRateRegime} - The regime to get the value from
|
||||
* @returns {int} - The value from the specified regime
|
||||
*/
|
||||
int getCustomRefreshRate(RefreshRateManager::RefreshRateRegime regime) const;
|
||||
|
||||
/*@jsdoc
|
||||
* Gets the current refresh rate profile in use.
|
||||
* @function Performance.getRefreshRateProfile
|
||||
|
|
|
@ -100,7 +100,8 @@ void setupPreferences() {
|
|||
QStringList refreshRateProfiles
|
||||
{ QString::fromStdString(RefreshRateManager::refreshRateProfileToString(RefreshRateManager::RefreshRateProfile::ECO)),
|
||||
QString::fromStdString(RefreshRateManager::refreshRateProfileToString(RefreshRateManager::RefreshRateProfile::INTERACTIVE)),
|
||||
QString::fromStdString(RefreshRateManager::refreshRateProfileToString(RefreshRateManager::RefreshRateProfile::REALTIME)) };
|
||||
QString::fromStdString(RefreshRateManager::refreshRateProfileToString(RefreshRateManager::RefreshRateProfile::REALTIME)),
|
||||
QString::fromStdString(RefreshRateManager::refreshRateProfileToString(RefreshRateManager::RefreshRateProfile::CUSTOM)) };
|
||||
|
||||
preference->setItems(refreshRateProfiles);
|
||||
preferences->addPreference(preference);
|
||||
|
|
Loading…
Reference in a new issue