mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 09:29:16 +02:00
Merge pull request #5431 from jherico/homer
Limit the amount of time consumed by QML rendering
This commit is contained in:
commit
89d1e82f89
2 changed files with 16 additions and 6 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "FboCache.h"
|
||||
#include <PerfStat.h>
|
||||
#include <NumericalConstants.h>
|
||||
|
||||
class QMyQuickRenderControl : public QQuickRenderControl {
|
||||
protected:
|
||||
|
@ -44,7 +45,10 @@ Q_LOGGING_CATEGORY(offscreenFocus, "hifi.offscreen.focus")
|
|||
// Time between receiving a request to render the offscreen UI actually triggering
|
||||
// the render. Could possibly be increased depending on the framerate we expect to
|
||||
// achieve.
|
||||
static const int SMALL_INTERVAL = 5;
|
||||
static const int MAX_QML_FRAMERATE = 10;
|
||||
static const int MIN_RENDER_INTERVAL_US = USECS_PER_SECOND / MAX_QML_FRAMERATE;
|
||||
static const int MIN_TIMER_MS = 5;
|
||||
|
||||
|
||||
OffscreenQmlSurface::OffscreenQmlSurface() :
|
||||
_renderControl(new QMyQuickRenderControl), _fboCache(new FboCache) {
|
||||
|
@ -90,7 +94,6 @@ void OffscreenQmlSurface::create(QOpenGLContext* shareContext) {
|
|||
// When Quick says there is a need to render, we will not render immediately. Instead,
|
||||
// a timer with a small interval is used to get better performance.
|
||||
_updateTimer.setSingleShot(true);
|
||||
_updateTimer.setInterval(SMALL_INTERVAL);
|
||||
connect(&_updateTimer, &QTimer::timeout, this, &OffscreenQmlSurface::updateQuick);
|
||||
|
||||
// Now hook up the signals. For simplicy we don't differentiate between
|
||||
|
@ -170,13 +173,18 @@ QObject* OffscreenQmlSurface::load(const QUrl& qmlSource, std::function<void(QQm
|
|||
|
||||
void OffscreenQmlSurface::requestUpdate() {
|
||||
_polish = true;
|
||||
if (!_updateTimer.isActive()) {
|
||||
_updateTimer.start();
|
||||
}
|
||||
requestRender();
|
||||
}
|
||||
|
||||
void OffscreenQmlSurface::requestRender() {
|
||||
if (!_updateTimer.isActive()) {
|
||||
auto now = usecTimestampNow();
|
||||
auto lastInterval = now - _lastRenderTime;
|
||||
if (lastInterval > MIN_RENDER_INTERVAL_US) {
|
||||
_updateTimer.setInterval(MIN_TIMER_MS);
|
||||
} else {
|
||||
_updateTimer.setInterval((MIN_RENDER_INTERVAL_US - lastInterval) / USECS_PER_MSEC);
|
||||
}
|
||||
_updateTimer.start();
|
||||
}
|
||||
}
|
||||
|
@ -243,6 +251,7 @@ void OffscreenQmlSurface::updateQuick() {
|
|||
if (_paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!makeCurrent()) {
|
||||
return;
|
||||
}
|
||||
|
@ -270,11 +279,11 @@ void OffscreenQmlSurface::updateQuick() {
|
|||
// Need a debug context with sync logging to figure out why.
|
||||
// for now just clear the errors
|
||||
glGetError();
|
||||
// Q_ASSERT(!glGetError());
|
||||
|
||||
_quickWindow->resetOpenGLState();
|
||||
|
||||
QOpenGLFramebufferObject::bindDefault();
|
||||
_lastRenderTime = usecTimestampNow();
|
||||
// Force completion of all the operations before we emit the texture as being ready for use
|
||||
glFinish();
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ private:
|
|||
QQuickItem* _rootItem{ nullptr };
|
||||
QTimer _updateTimer;
|
||||
FboCache* _fboCache;
|
||||
quint64 _lastRenderTime{ 0 };
|
||||
bool _polish{ true };
|
||||
bool _paused{ true };
|
||||
MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p; } };
|
||||
|
|
Loading…
Reference in a new issue