Remove QEglFSCursor's inheritance of QOpenGLFunctions

As QOpenGLContext can be destroyed
it's a bad idea to store QOpenGLFunctions
(which are QOpenGLContext bound)

This change remove the inheritance and replaces it with
querying the functions per call.

Change-Id: I2f3104b62f395f3e65337a15d0a0835383b66e16
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
(cherry picked from commit 6160635c9d0616882ae826c6166d1d583d66827b)
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Thomas Senyk 2022-12-16 10:45:22 +01:00
parent 124a8b6cdb
commit 27747feb59
2 changed files with 25 additions and 26 deletions

View File

@ -8,6 +8,7 @@
#include <qpa/qwindowsysteminterface.h> #include <qpa/qwindowsysteminterface.h>
#include <QtGui/QOpenGLContext> #include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFunctions>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QJsonDocument> #include <QtCore/QJsonDocument>
#include <QtCore/QJsonArray> #include <QtCore/QJsonArray>
@ -117,15 +118,17 @@ void QEglFSCursor::createShaderPrograms()
void QEglFSCursor::createCursorTexture(uint *texture, const QImage &image) void QEglFSCursor::createCursorTexture(uint *texture, const QImage &image)
{ {
Q_ASSERT(QOpenGLContext::currentContext());
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
if (!*texture) if (!*texture)
glGenTextures(1, texture); f->glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture); f->glBindTexture(GL_TEXTURE_2D, *texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); f->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); f->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); f->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); f->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0 /* level */, GL_RGBA, image.width(), image.height(), 0 /* border */, f->glTexImage2D(GL_TEXTURE_2D, 0 /* level */, GL_RGBA, image.width(), image.height(), 0 /* border */,
GL_RGBA, GL_UNSIGNED_BYTE, image.constBits()); GL_RGBA, GL_UNSIGNED_BYTE, image.constBits());
} }
@ -338,8 +341,8 @@ void QEglFSCursor::paintOnScreen()
// to deal with the changes we make. // to deal with the changes we make.
struct StateSaver struct StateSaver
{ {
StateSaver() { StateSaver(QOpenGLFunctions* func) {
f = QOpenGLContext::currentContext()->functions(); f = func;
vaoHelper = QOpenGLVertexArrayObjectHelper::vertexArrayObjectHelperForContext(QOpenGLContext::currentContext()); vaoHelper = QOpenGLVertexArrayObjectHelper::vertexArrayObjectHelperForContext(QOpenGLContext::currentContext());
static bool windowsChecked = false; static bool windowsChecked = false;
@ -430,11 +433,9 @@ struct StateSaver
void QEglFSCursor::draw(const QRectF &r) void QEglFSCursor::draw(const QRectF &r)
{ {
StateSaver stateSaver; Q_ASSERT(QOpenGLContext::currentContext());
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
// one time initialization StateSaver stateSaver(f);
if (!QOpenGLFunctions::d_ptr)
initializeOpenGLFunctions();
QEglFSCursorData &gfx = static_cast<QEglFSContext*>(QOpenGLContext::currentContext()->handle())->cursorData; QEglFSCursorData &gfx = static_cast<QEglFSContext*>(QOpenGLContext::currentContext()->handle())->cursorData;
if (!gfx.program) { if (!gfx.program) {
@ -483,13 +484,13 @@ void QEglFSCursor::draw(const QRectF &r)
s2, t1 s2, t1
}; };
glActiveTexture(GL_TEXTURE0); f->glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, cursorTexture); f->glBindTexture(GL_TEXTURE_2D, cursorTexture);
if (stateSaver.vaoHelper->isValid()) if (stateSaver.vaoHelper->isValid())
stateSaver.vaoHelper->glBindVertexArray(0); stateSaver.vaoHelper->glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0); f->glBindBuffer(GL_ARRAY_BUFFER, 0);
gfx.program->enableAttributeArray(0); gfx.program->enableAttributeArray(0);
gfx.program->enableAttributeArray(1); gfx.program->enableAttributeArray(1);
@ -499,13 +500,13 @@ void QEglFSCursor::draw(const QRectF &r)
gfx.program->setUniformValue(gfx.textureEntry, 0); gfx.program->setUniformValue(gfx.textureEntry, 0);
gfx.program->setUniformValue(gfx.matEntry, m_rotationMatrix); gfx.program->setUniformValue(gfx.matEntry, m_rotationMatrix);
glDisable(GL_CULL_FACE); f->glDisable(GL_CULL_FACE);
glFrontFace(GL_CCW); f->glFrontFace(GL_CCW);
glEnable(GL_BLEND); f->glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); f->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST); // disable depth testing to make sure cursor is always on top f->glDisable(GL_DEPTH_TEST); // disable depth testing to make sure cursor is always on top
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
gfx.program->disableAttributeArray(0); gfx.program->disableAttributeArray(0);
gfx.program->disableAttributeArray(1); gfx.program->disableAttributeArray(1);

View File

@ -20,7 +20,6 @@
#include <qpa/qplatformscreen.h> #include <qpa/qplatformscreen.h>
#include <QtOpenGL/QOpenGLShaderProgram> #include <QtOpenGL/QOpenGLShaderProgram>
#include <QtGui/QMatrix4x4> #include <QtGui/QMatrix4x4>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/private/qinputdevicemanager_p.h> #include <QtGui/private/qinputdevicemanager_p.h>
#include <QtCore/qlist.h> #include <QtCore/qlist.h>
@ -58,7 +57,6 @@ struct QEglFSCursorData {
}; };
class Q_EGLFS_EXPORT QEglFSCursor : public QPlatformCursor class Q_EGLFS_EXPORT QEglFSCursor : public QPlatformCursor
, protected QOpenGLFunctions
{ {
Q_OBJECT Q_OBJECT
public: public: