From 8303a4cdf8336afd8bc83e4e864d0e9dec6707bc Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 31 Aug 2020 21:52:24 +0100 Subject: [PATCH] Make GL Context current when deleting lanczos textures in timer hander. A timer could have fired at any time. We process mulitple QtQuickViews on timers which change the GL context. Deleting a kwin GLTexture calls glDeleteTextures/glDeleteFramebuffers. Surprisingly I haven't seen a crash report from this, but it doesn't look right. --- plugins/scenes/opengl/lanczosfilter.cpp | 7 ++++++- plugins/scenes/opengl/lanczosfilter.h | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/scenes/opengl/lanczosfilter.cpp b/plugins/scenes/opengl/lanczosfilter.cpp index a2a8c3f016..4582550dc4 100644 --- a/plugins/scenes/opengl/lanczosfilter.cpp +++ b/plugins/scenes/opengl/lanczosfilter.cpp @@ -32,7 +32,7 @@ namespace KWin { -LanczosFilter::LanczosFilter(QObject* parent) +LanczosFilter::LanczosFilter(Scene *parent) : QObject(parent) , m_offscreenTex(nullptr) , m_offscreenTarget(nullptr) @@ -40,6 +40,7 @@ LanczosFilter::LanczosFilter(QObject* parent) , m_shader(nullptr) , m_uOffsets(0) , m_uKernel(0) + , m_scene(parent) { } @@ -379,6 +380,8 @@ void LanczosFilter::timerEvent(QTimerEvent *event) if (event->timerId() == m_timer.timerId()) { m_timer.stop(); + m_scene->makeOpenGLContextCurrent(); + delete m_offscreenTarget; delete m_offscreenTex; m_offscreenTarget = nullptr; @@ -387,6 +390,8 @@ void LanczosFilter::timerEvent(QTimerEvent *event) workspace()->forEachToplevel([this](Toplevel *toplevel) { discardCacheTexture(toplevel->effectWindow()); }); + + m_scene->doneOpenGLContextCurrent(); } } diff --git a/plugins/scenes/opengl/lanczosfilter.h b/plugins/scenes/opengl/lanczosfilter.h index f847f13a55..56033c1b5c 100644 --- a/plugins/scenes/opengl/lanczosfilter.h +++ b/plugins/scenes/opengl/lanczosfilter.h @@ -26,13 +26,14 @@ class WindowPaintData; class GLTexture; class GLRenderTarget; class GLShader; +class Scene; class LanczosFilter : public QObject { Q_OBJECT public: - explicit LanczosFilter(QObject* parent = nullptr); + explicit LanczosFilter(Scene *parent); ~LanczosFilter() override; void performPaint(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data); @@ -55,6 +56,7 @@ private: int m_uKernel; QVector2D m_offsets[16]; QVector4D m_kernel[16]; + Scene *m_scene; }; } // namespace