Check throttle before idling/painting

This commit is contained in:
Zach Pomerantz 2016-05-23 19:04:35 -07:00
parent a8b359dd60
commit 7dabce9cff
2 changed files with 26 additions and 22 deletions

View file

@ -174,7 +174,6 @@ static const QString FBX_EXTENSION = ".fbx";
static const QString OBJ_EXTENSION = ".obj";
static const QString AVA_JSON_EXTENSION = ".ava.json";
static const int MSECS_PER_SEC = 1000;
static const int MIRROR_VIEW_TOP_PADDING = 5;
static const int MIRROR_VIEW_LEFT_PADDING = 10;
static const int MIRROR_VIEW_WIDTH = 265;
@ -633,7 +632,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));
// update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one
const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SEC;
const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SECOND;
auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
connect(&locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);
@ -1828,9 +1827,9 @@ bool Application::event(QEvent* event) {
// Presentation/painting logic
// TODO: Decouple presentation and painting loops
static bool isPainting = false;
static bool isPaintingThrottled = false;
if ((int)event->type() == (int)Present) {
if (isPainting) {
if (isPaintingThrottled) {
// If painting (triggered by presentation) is hogging the main thread,
// repost as low priority to avoid hanging the GUI.
// This has the effect of allowing presentation to exceed the paint budget by X times and
@ -1838,14 +1837,17 @@ bool Application::event(QEvent* event) {
// (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).
removePostedEvents(this, Present);
postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);
isPainting = false;
isPaintingThrottled = false;
return true;
}
idle();
postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
isPainting = true;
float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
if (shouldPaint(nsecsElapsed)) {
_lastTimeUpdated.start();
idle(nsecsElapsed);
postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
}
isPaintingThrottled = true;
return true;
} else if ((int)event->type() == (int)Paint) {
@ -1855,7 +1857,7 @@ bool Application::event(QEvent* event) {
paintGL();
isPainting = false;
isPaintingThrottled = false;
return true;
}
@ -2639,10 +2641,9 @@ bool Application::acceptSnapshot(const QString& urlString) {
static uint32_t _renderedFrameIndex { INVALID_FRAME };
void Application::idle() {
// idle is called on a queued connection, so make sure we should be here.
if (_inPaint || _aboutToQuit) {
return;
bool Application::shouldPaint(float nsecsElapsed) {
if (_aboutToQuit) {
return false;
}
auto displayPlugin = getActiveDisplayPlugin();
@ -2661,16 +2662,21 @@ void Application::idle() {
}
#endif
float msecondsSinceLastUpdate = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_USEC / USECS_PER_MSEC;
float msecondsSinceLastUpdate = nsecsElapsed / NSECS_PER_USEC / USECS_PER_MSEC;
// Throttle if requested
if (displayPlugin->isThrottled() && (msecondsSinceLastUpdate < THROTTLED_SIM_FRAME_PERIOD_MS)) {
return;
return false;
}
// Sync up the _renderedFrameIndex
_renderedFrameIndex = displayPlugin->presentCount();
return true;
}
void Application::idle(float nsecsElapsed) {
// Update the deadlock watchdog
updateHeartbeat();
@ -2687,7 +2693,7 @@ void Application::idle() {
PROFILE_RANGE(__FUNCTION__);
float secondsSinceLastUpdate = msecondsSinceLastUpdate / MSECS_PER_SECOND;
float secondsSinceLastUpdate = nsecsElapsed / NSECS_PER_MSEC / MSECS_PER_SECOND;
// If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus.
if (_keyboardDeviceHasFocus && offscreenUi && offscreenUi->getWindow()->activeFocusItem() != offscreenUi->getRootItem()) {
@ -2697,9 +2703,6 @@ void Application::idle() {
_keyboardDeviceHasFocus = true;
}
// We're going to execute idle processing, so restart the last idle timer
_lastTimeUpdated.start();
checkChangeCursor();
Stats::getInstance()->updateStats();
@ -2926,7 +2929,7 @@ void Application::loadSettings() {
}
void Application::saveSettings() const {
sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SEC);
sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SECOND);
DependencyManager::get<AudioClient>()->saveSettings();
DependencyManager::get<LODManager>()->saveSettings();

View file

@ -329,7 +329,8 @@ private:
void cleanupBeforeQuit();
void idle();
bool shouldPaint(float nsecsElapsed);
void idle(float nsecsElapsed);
void update(float deltaTime);
// Various helper functions called during update()