From 47e38b7141a9e1ff3c93b37a2df24a8ae7d9781c Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 2 Aug 2021 00:11:27 +0100 Subject: [PATCH] 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 --- src/scripting/thumbnailitem.cpp | 18 ++++++++++++++---- src/scripting/thumbnailitem.h | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/scripting/thumbnailitem.cpp b/src/scripting/thumbnailitem.cpp index f272c2b16d..05687e6095 100644 --- a/src/scripting/thumbnailitem.cpp +++ b/src/scripting/thumbnailitem.cpp @@ -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(); diff --git a/src/scripting/thumbnailitem.h b/src/scripting/thumbnailitem.h index 363d79341a..dfed036b5f 100644 --- a/src/scripting/thumbnailitem.h +++ b/src/scripting/thumbnailitem.h @@ -80,7 +80,8 @@ protected: qreal m_devicePixelRatio = 1; private: - void handleCompositingToggled(); + void updateFrameRenderingConnection(); + QMetaObject::Connection m_frameRenderingConnection; QSize m_sourceSize; };