refresh rate controller

This commit is contained in:
danteruiz 2019-04-30 16:44:47 -07:00 committed by Sam Gateau
parent c1ee4deb12
commit f65f28c52a
3 changed files with 55 additions and 27 deletions

View file

@ -4064,9 +4064,6 @@ bool Application::event(QEvent* event) {
case QEvent::KeyRelease:
keyReleaseEvent(static_cast<QKeyEvent*>(event));
return true;
case QEvent::FocusIn:
focusInEvent(static_cast<QFocusEvent*>(event));
return true;
case QEvent::FocusOut:
focusOutEvent(static_cast<QFocusEvent*>(event));
return true;
@ -4109,6 +4106,17 @@ bool Application::eventFilter(QObject* object, QEvent* event) {
return true;
}
auto eventType = event->type();
if (eventType == QEvent::KeyPress || eventType == QEvent::KeyRelease || eventType == QEvent::MouseMove) {
RefreshRateManager& refreshRateManager = getRefreshRateManager();
auto refreshRateRegime = refreshRateManager.getRefreshRateRegime();
if (refreshRateRegime == RefreshRateManager::RefreshRateRegime::RUNNING ||
refreshRateRegime == RefreshRateManager::RefreshRateRegime::INACTIVE) {
getRefreshRateManager().resetInactiveTimer();
}
}
if (event->type() == QEvent::Leave) {
getApplicationCompositor().handleLeaveEvent();
}
@ -4420,13 +4428,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
}
void Application::focusInEvent(QFocusEvent* event) {
if (!_aboutToQuit && _startUpFinished) {
getRefreshRateManager().setRefreshRateRegime(RefreshRateManager::RefreshRateRegime::RUNNING);
}
}
void Application::focusOutEvent(QFocusEvent* event) {
auto inputPlugins = PluginManager::getInstance()->getInputPlugins();
foreach(auto inputPlugin, inputPlugins) {
@ -4434,10 +4435,6 @@ void Application::focusOutEvent(QFocusEvent* event) {
inputPlugin->pluginFocusOutEvent();
}
}
if (!_aboutToQuit && _startUpFinished) {
getRefreshRateManager().setRefreshRateRegime(RefreshRateManager::RefreshRateRegime::UNFOCUS);
}
// FIXME spacemouse code still needs cleanup
#if 0
//SpacemouseDevice::getInstance().focusOutEvent();
@ -8549,11 +8546,20 @@ void Application::activeChanged(Qt::ApplicationState state) {
switch (state) {
case Qt::ApplicationActive:
_isForeground = true;
if (!_aboutToQuit && _startUpFinished) {
getRefreshRateManager().setRefreshRateRegime(RefreshRateManager::RefreshRateRegime::RUNNING);
}
break;
case Qt::ApplicationSuspended:
break;
case Qt::ApplicationHidden:
break;
case Qt::ApplicationInactive:
if (!_aboutToQuit && _startUpFinished) {
getRefreshRateManager().setRefreshRateRegime(RefreshRateManager::RefreshRateRegime::UNFOCUS);
}
break;
default:
_isForeground = false;
break;

View file

@ -26,7 +26,7 @@ static const std::array<std::string, RefreshRateManager::RefreshRateProfile::PRO
{ { "Eco", "Interactive", "Realtime" } };
static const std::array<std::string, RefreshRateManager::RefreshRateRegime::REGIME_NUM> REFRESH_RATE_REGIME_TO_STRING =
{ { "Running", "Unfocus", "Minimized", "StartUp", "ShutDown" } };
{ { "Running", "Unfocus", "Minimized", "StartUp", "ShutDown", "Inactive" } };
static const std::array<std::string, RefreshRateManager::UXMode::UX_NUM> UX_MODE_TO_STRING =
{ { "Desktop", "HMD" } };
@ -36,21 +36,20 @@ static const std::map<std::string, RefreshRateManager::RefreshRateProfile> REFRE
{ "Interactive", RefreshRateManager::RefreshRateProfile::INTERACTIVE },
{ "Realtime", RefreshRateManager::RefreshRateProfile::REALTIME } };
static const std::array<int, RefreshRateManager::RefreshRateProfile::PROFILE_NUM> RUNNING_REGIME_PROFILES =
{ { 5, 20, 60 } };
static const std::array<int, RefreshRateManager::RefreshRateRegime::REGIME_NUM> ECO_PROFILE =
{ { 5, 5, 2, 30, 30, 4 } };
static const std::array<int, RefreshRateManager::RefreshRateProfile::PROFILE_NUM> UNFOCUS_REGIME_PROFILES =
{ { 5, 5, 10 } };
static const std::array<int, RefreshRateManager::RefreshRateRegime::REGIME_NUM> INTERACTIVE_PROFILE =
{ { 25, 5, 2, 30, 30, 20 } };
static const std::array<int, RefreshRateManager::RefreshRateProfile::PROFILE_NUM> MINIMIZED_REGIME_PROFILE =
{ { 2, 2, 2 } };
static const std::array<int, RefreshRateManager::RefreshRateRegime::REGIME_NUM> REALTIME_PROFILE =
{ { 60, 10, 2, 30, 30, 30} };
static const std::array<int, RefreshRateManager::RefreshRateProfile::PROFILE_NUM> START_AND_SHUTDOWN_REGIME_PROFILES =
{ { 30, 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<std::array<int, RefreshRateManager::RefreshRateProfile::PROFILE_NUM>, RefreshRateManager::RefreshRateRegime::REGIME_NUM> REFRESH_RATE_REGIMES =
{ { RUNNING_REGIME_PROFILES, UNFOCUS_REGIME_PROFILES, MINIMIZED_REGIME_PROFILE,
START_AND_SHUTDOWN_REGIME_PROFILES, START_AND_SHUTDOWN_REGIME_PROFILES } };
static const int INACTIVE_TIMER_LIMIT = 3000;
std::string RefreshRateManager::refreshRateProfileToString(RefreshRateManager::RefreshRateProfile refreshRateProfile) {
@ -71,6 +70,21 @@ std::string RefreshRateManager::uxModeToString(RefreshRateManager::RefreshRateMa
RefreshRateManager::RefreshRateManager() {
_refreshRateProfile = (RefreshRateManager::RefreshRateProfile) _refreshRateMode.get();
_inactiveTimer->setInterval(INACTIVE_TIMER_LIMIT);
_inactiveTimer->setSingleShot(true);
QObject::connect(_inactiveTimer.get(), &QTimer::timeout, [&] {
if (_uxMode == RefreshRateManager::UXMode::DESKTOP &&
getRefreshRateRegime() == RefreshRateManager::RefreshRateRegime::RUNNING) {
setRefreshRateRegime(RefreshRateManager::RefreshRateRegime::INACTIVE);
}
});
}
void RefreshRateManager::resetInactiveTimer() {
if (_uxMode == RefreshRateManager::UXMode::DESKTOP) {
_inactiveTimer->start();
setRefreshRateRegime(RefreshRateManager::RefreshRateRegime::RUNNING);
}
}
void RefreshRateManager::setRefreshRateProfile(RefreshRateManager::RefreshRateProfile refreshRateProfile) {
@ -123,7 +137,7 @@ void RefreshRateManager::updateRefreshRateController() const {
_refreshRateProfile == RefreshRateManager::RefreshRateProfile::INTERACTIVE) {
targetRefreshRate = getInteractiveRefreshRate();
} else {
targetRefreshRate = REFRESH_RATE_REGIMES[_refreshRateRegime][_refreshRateProfile];
targetRefreshRate = REFRESH_RATE_PROFILES[_refreshRateProfile][_refreshRateRegime];
}
} else {
targetRefreshRate = HMD_TARGET_RATE;

View file

@ -15,6 +15,8 @@
#include <map>
#include <string>
#include <QTimer>
#include <SettingHandle.h>
#include <shared/ReadWriteLockable.h>
@ -33,6 +35,7 @@ public:
MINIMIZED,
STARTUP,
SHUTDOWN,
INACTIVE,
REGIME_NUM
};
@ -60,6 +63,8 @@ public:
void setInteractiveRefreshRate(int refreshRate);
int getInteractiveRefreshRate() const;
void resetInactiveTimer();
static std::string refreshRateProfileToString(RefreshRateProfile refreshRateProfile);
static RefreshRateProfile refreshRateProfileFromString(std::string refreshRateProfile);
static std::string uxModeToString(UXMode uxMode);
@ -78,6 +83,9 @@ private:
Setting::Handle<int> _refreshRateMode { "refreshRateProfile", INTERACTIVE };
std::function<void(int)> _refreshRateOperator { nullptr };
std::shared_ptr<QTimer> _inactiveTimer { std::make_shared<QTimer>() };
};
#endif