mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 04:08:13 +02:00
Limit the amount of time consumed by rendering QML
This commit is contained in:
parent
e24395a226
commit
7be33dcb58
2 changed files with 16 additions and 6 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "FboCache.h"
|
#include "FboCache.h"
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
|
#include <NumericalConstants.h>
|
||||||
|
|
||||||
class QMyQuickRenderControl : public QQuickRenderControl {
|
class QMyQuickRenderControl : public QQuickRenderControl {
|
||||||
protected:
|
protected:
|
||||||
|
@ -44,7 +45,10 @@ Q_LOGGING_CATEGORY(offscreenFocus, "hifi.offscreen.focus")
|
||||||
// Time between receiving a request to render the offscreen UI actually triggering
|
// 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
|
// the render. Could possibly be increased depending on the framerate we expect to
|
||||||
// achieve.
|
// 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() :
|
OffscreenQmlSurface::OffscreenQmlSurface() :
|
||||||
_renderControl(new QMyQuickRenderControl), _fboCache(new FboCache) {
|
_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,
|
// 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.
|
// a timer with a small interval is used to get better performance.
|
||||||
_updateTimer.setSingleShot(true);
|
_updateTimer.setSingleShot(true);
|
||||||
_updateTimer.setInterval(SMALL_INTERVAL);
|
|
||||||
connect(&_updateTimer, &QTimer::timeout, this, &OffscreenQmlSurface::updateQuick);
|
connect(&_updateTimer, &QTimer::timeout, this, &OffscreenQmlSurface::updateQuick);
|
||||||
|
|
||||||
// Now hook up the signals. For simplicy we don't differentiate between
|
// 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() {
|
void OffscreenQmlSurface::requestUpdate() {
|
||||||
_polish = true;
|
_polish = true;
|
||||||
if (!_updateTimer.isActive()) {
|
requestRender();
|
||||||
_updateTimer.start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenQmlSurface::requestRender() {
|
void OffscreenQmlSurface::requestRender() {
|
||||||
if (!_updateTimer.isActive()) {
|
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();
|
_updateTimer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,6 +251,7 @@ void OffscreenQmlSurface::updateQuick() {
|
||||||
if (_paused) {
|
if (_paused) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!makeCurrent()) {
|
if (!makeCurrent()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -270,11 +279,11 @@ void OffscreenQmlSurface::updateQuick() {
|
||||||
// Need a debug context with sync logging to figure out why.
|
// Need a debug context with sync logging to figure out why.
|
||||||
// for now just clear the errors
|
// for now just clear the errors
|
||||||
glGetError();
|
glGetError();
|
||||||
// Q_ASSERT(!glGetError());
|
|
||||||
|
|
||||||
_quickWindow->resetOpenGLState();
|
_quickWindow->resetOpenGLState();
|
||||||
|
|
||||||
QOpenGLFramebufferObject::bindDefault();
|
QOpenGLFramebufferObject::bindDefault();
|
||||||
|
_lastRenderTime = usecTimestampNow();
|
||||||
// Force completion of all the operations before we emit the texture as being ready for use
|
// Force completion of all the operations before we emit the texture as being ready for use
|
||||||
glFinish();
|
glFinish();
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,7 @@ private:
|
||||||
QQuickItem* _rootItem{ nullptr };
|
QQuickItem* _rootItem{ nullptr };
|
||||||
QTimer _updateTimer;
|
QTimer _updateTimer;
|
||||||
FboCache* _fboCache;
|
FboCache* _fboCache;
|
||||||
|
quint64 _lastRenderTime{ 0 };
|
||||||
bool _polish{ true };
|
bool _polish{ true };
|
||||||
bool _paused{ true };
|
bool _paused{ true };
|
||||||
MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p; } };
|
MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p; } };
|
||||||
|
|
Loading…
Reference in a new issue