diff --git a/src/libkwineffects/kwingltexture.cpp b/src/libkwineffects/kwingltexture.cpp index d786e2f7c9..81f3301055 100644 --- a/src/libkwineffects/kwingltexture.cpp +++ b/src/libkwineffects/kwingltexture.cpp @@ -82,7 +82,8 @@ GLTexture::GLTexture(const QImage& image, GLenum target) d->updateMatrix(); - create(); + const bool created = create(); + Q_ASSERT(created); bind(); if (!GLPlatform::instance()->isGLES()) { diff --git a/src/plugins/scenes/opengl/scene_opengl.cpp b/src/plugins/scenes/opengl/scene_opengl.cpp index f6208d1ae4..d84c190daa 100644 --- a/src/plugins/scenes/opengl/scene_opengl.cpp +++ b/src/plugins/scenes/opengl/scene_opengl.cpp @@ -296,23 +296,33 @@ void SceneOpenGL2::paintCursor(const QRegion &rendered) return; } + auto newTexture = [this] { + const QImage img = Cursors::self()->currentCursor()->image(); + if (img.isNull()) { + m_cursorTextureDirty = false; + return; + } + m_cursorTexture.reset(new GLTexture(img)); + m_cursorTexture->setWrapMode(GL_CLAMP_TO_EDGE); + m_cursorTextureDirty = false; + }; + // lazy init texture cursor only in case we need software rendering if (!m_cursorTexture) { - auto updateCursorTexture = [this] { - // don't paint if no image for cursor is set - const QImage img = Cursors::self()->currentCursor()->image(); - if (img.isNull()) { - return; - } - m_cursorTexture.reset(new GLTexture(img)); - m_cursorTexture->setWrapMode(GL_CLAMP_TO_EDGE); - }; - - // init now - updateCursorTexture(); + newTexture(); // handle shape update on case cursor image changed - connect(Cursors::self(), &Cursors::currentCursorChanged, this, updateCursorTexture); + connect(Cursors::self(), &Cursors::currentCursorChanged, this, [this] { + m_cursorTextureDirty = true; + }); + } else if (m_cursorTextureDirty) { + const QImage image = Cursors::self()->currentCursor()->image(); + if (image.size() == m_cursorTexture->size()) { + m_cursorTexture->update(image); + m_cursorTextureDirty = false; + } else { + newTexture(); + } } // get cursor position in projection coordinates diff --git a/src/plugins/scenes/opengl/scene_opengl.h b/src/plugins/scenes/opengl/scene_opengl.h index 8dacb9451d..fa732d3b63 100644 --- a/src/plugins/scenes/opengl/scene_opengl.h +++ b/src/plugins/scenes/opengl/scene_opengl.h @@ -115,6 +115,7 @@ private: LanczosFilter *m_lanczosFilter; QScopedPointer m_cursorTexture; + bool m_cursorTextureDirty = false; QMatrix4x4 m_projectionMatrix; QMatrix4x4 m_screenProjectionMatrix; GLuint vao;