summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-04-17 11:20:46 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-04-17 16:00:43 +0200
commitbad2ac47f8a6a43df62208e80e114fdd554ed542 (patch)
tree85b5ad6c39e183694b1c2b376a83508282980b44 /src/opengl
parentd6272d774c7415186aa398e59f234d0073458072 (diff)
Resolve OpenGL version functions in thread-safe manner
In 73f3f501f331444b3f188b21db7265f723e4f383, the classes were moved out of Qt Gui, and a mechanism to attach them to the QOpenGLContext was implemented using a QMap and a connection on destroyed to delete it. This solution was not thread-safe, so the suggestion was to either add a mutex or to make an opaque pointer for the storage in the (thread-affine) QOpenGLContextPrivate. I decided to go with the latter. A solution using hash lookups and mutexes seems to complex when the only benefit is to avoid forward declarations from Qt Gui to Qt OpenGL in private API. Especially since this dependency already exists with the "textureFunctions", which serve the same purpose, although the destructor is being passed in as an explicit function pointer there, probably because the ambition was to use a forward declaration rather than a superclass. Fixes: QTBUG-82742 Change-Id: I5c6b82c5b33d9cb73ad1ec05d3fc3e87a9eae4cf Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/qopenglversionfunctions.cpp17
-rw-r--r--src/opengl/qopenglversionfunctions_p.h10
2 files changed, 10 insertions, 17 deletions
diff --git a/src/opengl/qopenglversionfunctions.cpp b/src/opengl/qopenglversionfunctions.cpp
index 61794fdec9..64d9d11218 100644
--- a/src/opengl/qopenglversionfunctions.cpp
+++ b/src/opengl/qopenglversionfunctions.cpp
@@ -68,19 +68,12 @@ QOpenGLContextVersionData::~QOpenGLContextVersionData()
QOpenGLContextVersionData *QOpenGLContextVersionData::forContext(QOpenGLContext *context)
{
- auto *data = contextData.value(context);
- if (!data) {
- data = new QOpenGLContextVersionData;
- // The data will live as long as the context. It could potentially be an opaque pointer
- // member of QOpenGLContextPrivate, but this avoids polluting QOpenGLContext with version
- // functions specifics
- QObject::connect(context, &QObject::destroyed, context, [data](){ delete data; }, Qt::DirectConnection);
- contextData[context] = data;
- }
- return data;
-}
+ QOpenGLContextPrivate *context_d = QOpenGLContextPrivate::get(context);
+ if (context_d->versionFunctions == nullptr)
+ context_d->versionFunctions = new QOpenGLContextVersionData;
-QMap<QOpenGLContext *, QOpenGLContextVersionData *> QOpenGLContextVersionData::contextData;
+ return static_cast<QOpenGLContextVersionData *>(context_d->versionFunctions);
+}
#define QT_OPENGL_COUNT_FUNCTIONS(ret, name, args) +1
#define QT_OPENGL_FUNCTION_NAMES(ret, name, args) \
diff --git a/src/opengl/qopenglversionfunctions_p.h b/src/opengl/qopenglversionfunctions_p.h
index cd1bb480ce..cad4374e27 100644
--- a/src/opengl/qopenglversionfunctions_p.h
+++ b/src/opengl/qopenglversionfunctions_p.h
@@ -62,6 +62,8 @@
#include "qopenglversionfunctions.h"
+#include <QtGui/private/qopenglcontext_p.h>
+
#include <QtOpenGL/qtopenglglobal.h>
#include <QtOpenGL/QOpenGLVersionProfile>
#include <QtCore/QSet>
@@ -70,16 +72,14 @@ QT_BEGIN_NAMESPACE
class QAbstractOpenGLFunctions;
-class QOpenGLContextVersionData {
+class QOpenGLContextVersionData : public QOpenGLContextVersionFunctionHelper
+{
public:
QHash<QOpenGLVersionProfile, QAbstractOpenGLFunctions *> functions;
QOpenGLVersionFunctionsStorage functionsStorage;
QSet<QAbstractOpenGLFunctions *> externalFunctions;
- // TODO: who calls delete?
- ~QOpenGLContextVersionData();
+ ~QOpenGLContextVersionData() override;
static QOpenGLContextVersionData *forContext(QOpenGLContext *context);
-private:
- static QMap<QOpenGLContext *, QOpenGLContextVersionData *> contextData;
};
QT_END_NAMESPACE