Disconnect frame renders when ThumbnailItem has no window

It is perfectly valid to have a case where an item exists but has no
window. During these times the item will never be rendered.

Rather than guard in updateOffscreenTexture, it's more economical to
disable the frame rendering in the first place. Especially as then it's
easy to extend to item visibility.

BUG: 440318
This commit is contained in:
David Edmundson 2021-08-02 00:11:27 +01:00
parent cf9c60a0c0
commit 47e38b7141
2 changed files with 16 additions and 5 deletions

View file

@ -96,12 +96,14 @@ ThumbnailItemBase::ThumbnailItemBase(QQuickItem *parent)
: QQuickItem(parent)
{
setFlag(ItemHasContents);
handleCompositingToggled();
updateFrameRenderingConnection();
connect(Compositor::self(), &Compositor::aboutToToggleCompositing,
this, &ThumbnailItemBase::destroyOffscreenTexture);
connect(Compositor::self(), &Compositor::compositingToggled,
this, &ThumbnailItemBase::handleCompositingToggled);
this, &ThumbnailItemBase::updateFrameRenderingConnection);
connect(this, &QQuickItem::windowChanged,
this, &ThumbnailItemBase::updateFrameRenderingConnection);
}
ThumbnailItemBase::~ThumbnailItemBase()
@ -143,14 +145,21 @@ QSGTextureProvider *ThumbnailItemBase::textureProvider() const
return m_provider;
}
void ThumbnailItemBase::handleCompositingToggled()
void ThumbnailItemBase::updateFrameRenderingConnection()
{
disconnect(m_frameRenderingConnection);
if (!Compositor::self()) {
return;
}
Scene *scene = Compositor::self()->scene();
if (!window()) {
return;
}
if (scene && scene->compositingType() == OpenGLCompositing) {
connect(scene, &Scene::frameRendered, this, &ThumbnailItemBase::updateOffscreenTexture);
m_frameRenderingConnection = connect(scene, &Scene::frameRendered, this, &ThumbnailItemBase::updateOffscreenTexture);
}
}
@ -329,6 +338,7 @@ void WindowThumbnailItem::updateOffscreenTexture()
if (m_acquireFence || !m_dirty || !m_client) {
return;
}
Q_ASSERT(window());
const QRect geometry = m_client->frameGeometry();
QSize textureSize = geometry.size();

View file

@ -80,7 +80,8 @@ protected:
qreal m_devicePixelRatio = 1;
private:
void handleCompositingToggled();
void updateFrameRenderingConnection();
QMetaObject::Connection m_frameRenderingConnection;
QSize m_sourceSize;
};