From 25deaf5bda523ef53c574e997dae4b515be42931 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 11 May 2016 18:27:32 -0700 Subject: [PATCH] Repost missed Presents with low priority --- interface/src/Application.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3ba362e56d..3599303239 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1786,14 +1786,29 @@ bool Application::event(QEvent* event) { return false; } + static bool justPresented = false; if ((int)event->type() == (int)Present) { + if (justPresented) { + justPresented = false; + + // If 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 + // only dropping every (1/X) frames, instead of every ceil(X) frames. + // (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(Present)), Qt::LowEventPriority); + return true; + } + idle(); - removePostedEvents(this, Present); // clear pending presents so we don't clog the pipes return true; } else if ((int)event->type() == (int)Paint) { + justPresented = true; paintGL(); return true; - } else if ((int)event->type() == (int)Lambda) { + } + + if ((int)event->type() == (int)Lambda) { static_cast(event)->call(); return true; } @@ -2605,7 +2620,7 @@ void Application::idle() { _renderedFrameIndex = displayPlugin->presentCount(); // Request a paint ASAP - postEvent(this, new QEvent(static_cast(Paint)), Qt::HighEventPriority); + postEvent(this, new QEvent(static_cast(Paint)), Qt::HighEventPriority + 1); // Update the deadlock watchdog updateHeartbeat();