Commit 74b27555 authored by Paul Tvete's avatar Paul Tvete
Browse files

Only do pixel readback when requested

Don't grab frames when the client has not requested it. This should
improve local performance when we are animating at full FPS. This
can cause extra updates in the corner case where we are not animating
evenly and are unlucky with the timing.

Als add new logging category qt.vncserver.fps to show local and remote
FPS once per second.
parent e0e45e98
......@@ -11,7 +11,8 @@
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcVnc, "qt.vncserver");
Q_DECLARE_LOGGING_CATEGORY(lcVncFPS)
Q_LOGGING_CATEGORY(lcVncFPS, "qt.vncserver.fps");
QVncItem::QVncItem()
......@@ -174,17 +175,11 @@ void QVncItem::handleImageRequest()
{
if (!m_pendingImageRequest) {
m_pendingImageRequest = true;
// // Force redraw if we don't have a grab already
// if (m_vncServer->screenImage().isNull())
// emit requestSourceUpdate();
// if (m_provider) {
// //### Potential race condition if provider is changed/deleted??
// qDebug() << "INVOKING grabTexture";
// QMetaObject::invokeMethod(m_provider, [this](){grabTexture();});
// }
if (m_ungrabbedUpdate) {
// There has been an update since the last grab, so we need to
// request an update to make sure we get the new content.
update();
}
}
}
......@@ -228,10 +223,6 @@ void QVncItem::setRemoteInputEnabled(bool newRemoteInputEnabled)
//Must be invoked on render thread:
void QVncItem::grabTexture()
{
#ifdef EXTRA_EXTRA_DEBUG
qDebug() << "grabTexture" << m_pendingImageRequest;
#endif
auto *provider = textureProvider();
#ifdef EXTRA_EXTRA_DEBUG
qDebug() << "handle tex" << provider;
......@@ -291,7 +282,9 @@ void QVncItem::grabTexture()
GL_BGRA,
GL_UNSIGNED_BYTE,
newImg.bits());
qCDebug(lcVnc) << "glGetTexImage" << Qt::hex << glGetError();
# ifdef EXTRA_EXTRA_DEBUG
qDebug() << "glGetTexImage" << Qt::hex << glGetError();
# endif
#endif
}
}
......@@ -308,7 +301,9 @@ void QVncItem::grabTexture()
m_image = newImg;
m_imageFlipped = imgFlipped;
m_pendingImageRequest = false;
m_ungrabbedUpdate = false;
emit imageChanged();
m_grabCount++;
}
}
}
......@@ -319,15 +314,33 @@ QSGNode *QVncItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *data)
if (provider != m_provider) {
m_provider = provider;
qDebug() << "Got texture provider" << isTextureProvider() << textureProvider();
if (provider)
if (provider) // Make sure we call updatePaintNode for every frame
connect(provider, &QSGTextureProvider::textureChanged, this, &QQuickItem::update);
}
if (m_connectionActive)
grabTexture(); // TODO: rate-limit grabbing when server hasn't requested frame yet
if (m_connectionActive && m_pendingImageRequest)
grabTexture();
else
m_ungrabbedUpdate = true;
#ifdef EXTRA_EXTRA_DEBUG
static int c;
qDebug() << "Rendering frame" << c++;
#endif
if (lcVncFPS().isDebugEnabled()) {
if (!m_frameTimer.isValid()) {
m_frameTimer.start();
m_frameCount = 0;
} else {
m_frameCount++;
if (m_frameTimer.elapsed() >= 1000){
auto t = m_frameTimer.restart();
qCDebug(lcVncFPS) << "Rendered" << m_frameCount << "and grabbed" << m_grabCount
<< "frames in" << t << "ms. Local FPS:" << m_frameCount * 1000.0/t
<< "remote FPS:" << m_grabCount * 1000.0/t;
m_frameCount = 0;
m_grabCount = 0;
}
}
}
return QQuickItem::updatePaintNode(node, data);
}
......@@ -342,8 +355,10 @@ void QVncItem::setConnectionActive(bool newConnectionActive)
return;
m_connectionActive = newConnectionActive;
QQuickItemPrivate::get(this)->layer()->setEnabled(newConnectionActive);
if (m_connectionActive)
if (m_connectionActive) {
m_pendingImageRequest = true; //we know we're going to get a request soon
update();
}
emit connectionActiveChanged();
}
......
......@@ -69,6 +69,7 @@ private:
QSizeF m_uiScale = {1,1};
bool m_cursorHackTest = false;
bool m_pendingImageRequest = false;
bool m_ungrabbedUpdate = false;
QSGTextureProvider *m_provider = nullptr;
QImage m_image;
......@@ -76,6 +77,11 @@ private:
bool m_connectionActive = false;
int m_vncPort;
//Debug
QElapsedTimer m_frameTimer;
int m_frameCount = 0;
int m_grabCount = 0;
};
QT_END_NAMESPACE
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment