SceneOpenGL2::paintCursor make sure the OpenGL context is current

Instead of painting right away when Cursors::currentCursorChanged is
emitted, mark as dirty and call again when paintCursor is called.

BUG: 439134
This commit is contained in:
Aleix Pol 2021-07-10 01:24:27 +02:00 committed by Aleix Pol Gonzalez
parent 2977ae8e37
commit 23129c09ce
3 changed files with 26 additions and 14 deletions

View file

@ -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()) {

View file

@ -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

View file

@ -115,6 +115,7 @@ private:
LanczosFilter *m_lanczosFilter;
QScopedPointer<GLTexture> m_cursorTexture;
bool m_cursorTextureDirty = false;
QMatrix4x4 m_projectionMatrix;
QMatrix4x4 m_screenProjectionMatrix;
GLuint vao;