History

Check throttle before idling/painting

Zach Pomerantz committed 10 years ago

Commit 7dabce91 parent a8b359d2 files · +26 −22Browse files

Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all

Unified · Split

interface/src/Application.cpp+24−21
@@ -174,7 +174,6 @@ static const QString FBX_EXTENSION = ".fbx"; · 173 unmodified lines
174174 static const QString OBJ_EXTENSION = ".obj";
175175 static const QString AVA_JSON_EXTENSION = ".ava.json";
176176
177−static const int MSECS_PER_SEC = 1000;
178177 static const int MIRROR_VIEW_TOP_PADDING = 5;
179178 static const int MIRROR_VIEW_LEFT_PADDING = 10;
180179 static const int MIRROR_VIEW_WIDTH = 265;
@@ -633,7 +632,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 452 unmodified lines
633632 connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));
634633
635634 // update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one
636− const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SEC;
635+ const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * MSECS_PER_SECOND;
637636
638637 auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
639638 connect(&locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);
@@ -1828,9 +1827,9 @@ bool Application::event(QEvent* event) { · 1188 unmodified lines
18281827
18291828 // Presentation/painting logic
18301829 // TODO: Decouple presentation and painting loops
1831− static bool isPainting = false;
1830+ static bool isPaintingThrottled = false;
18321831 if ((int)event->type() == (int)Present) {
1833− if (isPainting) {
1832+ if (isPaintingThrottled) {
18341833 // If painting (triggered by presentation) is hogging the main thread,
18351834 // repost as low priority to avoid hanging the GUI.
18361835 // 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) { · 1 unmodified line
18381837 // (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).
18391838 removePostedEvents(this, Present);
18401839 postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);
1841− isPainting = false;
1840+ isPaintingThrottled = false;
18421841 return true;
18431842 }
18441843
1845− idle();
1846−
1847− postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
1848− isPainting = true;
1844+ float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
1845+ if (shouldPaint(nsecsElapsed)) {
1846+ _lastTimeUpdated.start();
1847+ idle(nsecsElapsed);
1848+ postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
1849+ }
1850+ isPaintingThrottled = true;
18491851
18501852 return true;
18511853 } else if ((int)event->type() == (int)Paint) {
@@ -1855,7 +1857,7 @@ bool Application::event(QEvent* event) { · 3 unmodified lines
18551857
18561858 paintGL();
18571859
1858− isPainting = false;
1860+ isPaintingThrottled = false;
18591861
18601862 return true;
18611863 }
@@ -2639,10 +2641,9 @@ bool Application::acceptSnapshot(const QString& urlString) { · 777 unmodified lines
26392641
26402642 static uint32_t _renderedFrameIndex { INVALID_FRAME };
26412643
2642−void Application::idle() {
2643− // idle is called on a queued connection, so make sure we should be here.
2644− if (_inPaint || _aboutToQuit) {
2645− return;
2644+bool Application::shouldPaint(float nsecsElapsed) {
2645+ if (_aboutToQuit) {
2646+ return false;
26462647 }
26472648
26482649 auto displayPlugin = getActiveDisplayPlugin();
@@ -2661,16 +2662,21 @@ void Application::idle() { · 12 unmodified lines
26612662 }
26622663 #endif
26632664
2664− float msecondsSinceLastUpdate = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_USEC / USECS_PER_MSEC;
2665+ float msecondsSinceLastUpdate = nsecsElapsed / NSECS_PER_USEC / USECS_PER_MSEC;
26652666
26662667 // Throttle if requested
26672668 if (displayPlugin->isThrottled() && (msecondsSinceLastUpdate < THROTTLED_SIM_FRAME_PERIOD_MS)) {
2668− return;
2669+ return false;
26692670 }
26702671
26712672 // Sync up the _renderedFrameIndex
26722673 _renderedFrameIndex = displayPlugin->presentCount();
26732674
2675+ return true;
2676+}
2677+
2678+void Application::idle(float nsecsElapsed) {
2679+
26742680 // Update the deadlock watchdog
26752681 updateHeartbeat();
26762682
@@ -2687,7 +2693,7 @@ void Application::idle() { · 10 unmodified lines
26872693
26882694 PROFILE_RANGE(__FUNCTION__);
26892695
2690− float secondsSinceLastUpdate = msecondsSinceLastUpdate / MSECS_PER_SECOND;
2696+ float secondsSinceLastUpdate = nsecsElapsed / NSECS_PER_MSEC / MSECS_PER_SECOND;
26912697
26922698 // If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus.
26932699 if (_keyboardDeviceHasFocus && offscreenUi && offscreenUi->getWindow()->activeFocusItem() != offscreenUi->getRootItem()) {
@@ -2697,9 +2703,6 @@ void Application::idle() { · 3 unmodified lines
26972703 _keyboardDeviceHasFocus = true;
26982704 }
26992705
2700− // We're going to execute idle processing, so restart the last idle timer
2701− _lastTimeUpdated.start();
2702−
27032706 checkChangeCursor();
27042707
27052708 Stats::getInstance()->updateStats();
@@ -2926,7 +2929,7 @@ void Application::loadSettings() { · 220 unmodified lines
29262929 }
29272930
29282931 void Application::saveSettings() const {
2929− sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SEC);
2932+ sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SECOND);
29302933 DependencyManager::get<AudioClient>()->saveSettings();
29312934 DependencyManager::get<LODManager>()->saveSettings();
29322935

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t