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
174static const QString OBJ_EXTENSION = ".obj";174static const QString OBJ_EXTENSION = ".obj";
175static const QString AVA_JSON_EXTENSION = ".ava.json";175static const QString AVA_JSON_EXTENSION = ".ava.json";
176 176
177static const int MSECS_PER_SEC = 1000;
178static const int MIRROR_VIEW_TOP_PADDING = 5;177static const int MIRROR_VIEW_TOP_PADDING = 5;
179static const int MIRROR_VIEW_LEFT_PADDING = 10;178static const int MIRROR_VIEW_LEFT_PADDING = 10;
180static const int MIRROR_VIEW_WIDTH = 265;179static const int MIRROR_VIEW_WIDTH = 265;
@@ -633,7 +632,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 452 unmodified lines
633 connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));632 connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));
634 633
635 // update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one634 // 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;
637 636
638 auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();637 auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
639 connect(&locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);638 connect(&locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);
@@ -1828,9 +1827,9 @@ bool Application::event(QEvent* event) { · 1188 unmodified lines
1828 1827
1829 // Presentation/painting logic1828 // Presentation/painting logic
1830 // TODO: Decouple presentation and painting loops1829 // TODO: Decouple presentation and painting loops
1831 static bool isPainting = false;1830 static bool isPaintingThrottled = false;
1832 if ((int)event->type() == (int)Present) {1831 if ((int)event->type() == (int)Present) {
1833 if (isPainting) {1832 if (isPaintingThrottled) {
1834 // If painting (triggered by presentation) is hogging the main thread,1833 // If painting (triggered by presentation) is hogging the main thread,
1835 // repost as low priority to avoid hanging the GUI.1834 // repost as low priority to avoid hanging the GUI.
1836 // This has the effect of allowing presentation to exceed the paint budget by X times and1835 // 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
1838 // (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).1837 // (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).
1839 removePostedEvents(this, Present);1838 removePostedEvents(this, Present);
1840 postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);1839 postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);
1841 isPainting = false;1840 isPaintingThrottled = false;
1842 return true;1841 return true;
1843 }1842 }
1844 1843
1845 idle();1844 float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
1846 1845 if (shouldPaint(nsecsElapsed)) {
1847 postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);1846 _lastTimeUpdated.start();
1848 isPainting = true;1847 idle(nsecsElapsed);
1848 postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
1849 }
1850 isPaintingThrottled = true;
1849 1851
1850 return true;1852 return true;
1851 } else if ((int)event->type() == (int)Paint) {1853 } else if ((int)event->type() == (int)Paint) {
@@ -1855,7 +1857,7 @@ bool Application::event(QEvent* event) { · 3 unmodified lines
1855 1857
1856 paintGL();1858 paintGL();
1857 1859
1858 isPainting = false;1860 isPaintingThrottled = false;
1859 1861
1860 return true;1862 return true;
1861 }1863 }
@@ -2639,10 +2641,9 @@ bool Application::acceptSnapshot(const QString& urlString) { · 777 unmodified lines
2639 2641
2640static uint32_t _renderedFrameIndex { INVALID_FRAME };2642static uint32_t _renderedFrameIndex { INVALID_FRAME };
2641 2643
2642void Application::idle() {2644bool Application::shouldPaint(float nsecsElapsed) {
2643 // idle is called on a queued connection, so make sure we should be here.2645 if (_aboutToQuit) {
2644 if (_inPaint || _aboutToQuit) {2646 return false;
2645 return;
2646 }2647 }
2647 2648
2648 auto displayPlugin = getActiveDisplayPlugin();2649 auto displayPlugin = getActiveDisplayPlugin();
@@ -2661,16 +2662,21 @@ void Application::idle() { · 12 unmodified lines
2661 }2662 }
2662#endif2663#endif
2663 2664
2664 float msecondsSinceLastUpdate = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_USEC / USECS_PER_MSEC;2665 float msecondsSinceLastUpdate = nsecsElapsed / NSECS_PER_USEC / USECS_PER_MSEC;
2665 2666
2666 // Throttle if requested2667 // Throttle if requested
2667 if (displayPlugin->isThrottled() && (msecondsSinceLastUpdate < THROTTLED_SIM_FRAME_PERIOD_MS)) {2668 if (displayPlugin->isThrottled() && (msecondsSinceLastUpdate < THROTTLED_SIM_FRAME_PERIOD_MS)) {
2668 return;2669 return false;
2669 }2670 }
2670 2671
2671 // Sync up the _renderedFrameIndex2672 // Sync up the _renderedFrameIndex
2672 _renderedFrameIndex = displayPlugin->presentCount();2673 _renderedFrameIndex = displayPlugin->presentCount();
2673 2674
2675 return true;
2676}
2677
2678void Application::idle(float nsecsElapsed) {
2679
2674 // Update the deadlock watchdog2680 // Update the deadlock watchdog
2675 updateHeartbeat();2681 updateHeartbeat();
2676 2682
@@ -2687,7 +2693,7 @@ void Application::idle() { · 10 unmodified lines
2687 2693
2688 PROFILE_RANGE(__FUNCTION__);2694 PROFILE_RANGE(__FUNCTION__);
2689 2695
2690 float secondsSinceLastUpdate = msecondsSinceLastUpdate / MSECS_PER_SECOND;2696 float secondsSinceLastUpdate = nsecsElapsed / NSECS_PER_MSEC / MSECS_PER_SECOND;
2691 2697
2692 // If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus.2698 // If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus.
2693 if (_keyboardDeviceHasFocus && offscreenUi && offscreenUi->getWindow()->activeFocusItem() != offscreenUi->getRootItem()) {2699 if (_keyboardDeviceHasFocus && offscreenUi && offscreenUi->getWindow()->activeFocusItem() != offscreenUi->getRootItem()) {
@@ -2697,9 +2703,6 @@ void Application::idle() { · 3 unmodified lines
2697 _keyboardDeviceHasFocus = true;2703 _keyboardDeviceHasFocus = true;
2698 }2704 }
2699 2705
2700 // We're going to execute idle processing, so restart the last idle timer
2701 _lastTimeUpdated.start();
2702
2703 checkChangeCursor();2706 checkChangeCursor();
2704 2707
2705 Stats::getInstance()->updateStats();2708 Stats::getInstance()->updateStats();
@@ -2926,7 +2929,7 @@ void Application::loadSettings() { · 220 unmodified lines
2926}2929}
2927 2930
2928void Application::saveSettings() const {2931void Application::saveSettings() const {
2929 sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SEC);2932 sessionRunTime.set(_sessionRunTimer.elapsed() / MSECS_PER_SECOND);
2930 DependencyManager::get<AudioClient>()->saveSettings();2933 DependencyManager::get<AudioClient>()->saveSettings();
2931 DependencyManager::get<LODManager>()->saveSettings();2934 DependencyManager::get<LODManager>()->saveSettings();
2932 2935

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