History

Merge pull request #10925 from jherico/overlay_performance

Fix terrible script performance when rendering load is too high

Brad Davis committed 9 years ago

Commit 8043caa2 parents 8a00efd cd11f5c3 files · +80 −69Browse files

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

Unified · Split

interface/src/Application.cpp+28−41
@@ -2729,56 +2729,43 @@ bool Application::importSVOFromURL(const QString& urlString) { · 2728 unmodified lines
27292729 return true;
27302730 }
27312731
2732+bool _renderRequested { false };
2733+
27322734 bool Application::event(QEvent* event) {
27332735 if (!Menu::getInstance()) {
27342736 return false;
27352737 }
27362738
2737− // Presentation/painting logic
2738− // TODO: Decouple presentation and painting loops
2739− static bool isPaintingThrottled = false;
2740− if ((int)event->type() == (int)Present) {
2741− if (isPaintingThrottled) {
2742− // If painting (triggered by presentation) is hogging the main thread,
2743− // repost as low priority to avoid hanging the GUI.
2744− // This has the effect of allowing presentation to exceed the paint budget by X times and
2745− // only dropping every (1/X) frames, instead of every ceil(X) frames
2746− // (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).
2747− removePostedEvents(this, Present);
2748− postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);
2749− isPaintingThrottled = false;
2739+ int type = event->type();
2740+ switch (type) {
2741+ case Event::Lambda:
2742+ static_cast<LambdaEvent*>(event)->call();
27502743 return true;
2751− }
2752−
2753− float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
2754− if (shouldPaint(nsecsElapsed)) {
2755− _lastTimeUpdated.start();
2756− idle(nsecsElapsed);
2757− postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
2758− }
2759− isPaintingThrottled = true;
27602744
2761− return true;
2762− } else if ((int)event->type() == (int)Paint) {
2763− // NOTE: This must be updated as close to painting as possible,
2764− // or AvatarInputs will mysteriously move to the bottom-right
2765− AvatarInputs::getInstance()->update();
2766−
2767− paintGL();
2768−
2769− isPaintingThrottled = false;
2770−
2771− return true;
2772− } else if ((int)event->type() == (int)Idle) {
2773− float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
2774− idle(nsecsElapsed);
2745+ case Event::Present:
2746+ if (!_renderRequested) {
2747+ float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed();
2748+ if (shouldPaint(nsecsElapsed)) {
2749+ _renderRequested = true;
2750+ _lastTimeUpdated.start();
2751+ idle(nsecsElapsed);
2752+ postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
2753+ }
2754+ }
2755+ return true;
27752756
2776− return true;
2777− }
2757+ case Event::Paint:
2758+ // NOTE: This must be updated as close to painting as possible,
2759+ // or AvatarInputs will mysteriously move to the bottom-right
2760+ AvatarInputs::getInstance()->update();
2761+ paintGL();
2762+ // wait for the next present event before starting idle / paint again
2763+ removePostedEvents(this, Present);
2764+ _renderRequested = false;
2765+ return true;
27782766
2779− if ((int)event->type() == (int)Lambda) {
2780− static_cast<LambdaEvent*>(event)->call();
2781− return true;
2767+ default:
2768+ break;
27822769 }
27832770
27842771 {