summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl/qopengldebug.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-08-01 08:51:18 +0200
committerLiang Qi <liang.qi@qt.io>2016-08-01 10:03:21 +0200
commit3cb7302480390e5149a9cf6f49ac1ca94ef63f97 (patch)
tree831134f1053214ab0d5ba4d406cf7b860ed7c578 /src/gui/opengl/qopengldebug.cpp
parent2ff1557937c398a7fb5cc7ba120e7ca3b5eacd36 (diff)
parentf24cc53cc27d8ed4be4c1d0d2df059dd6a6909a9 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: src/widgets/itemviews/qabstractitemview.cpp src/widgets/itemviews/qabstractitemview_p.h Change-Id: I54589b1365103cb1749186af92aab03a49c94b64
Diffstat (limited to 'src/gui/opengl/qopengldebug.cpp')
-rw-r--r--src/gui/opengl/qopengldebug.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp
index 24aa6094dd..f6c3af37dd 100644
--- a/src/gui/opengl/qopengldebug.cpp
+++ b/src/gui/opengl/qopengldebug.cpp
@@ -42,6 +42,7 @@
#include <QtCore/qvarlengtharray.h>
#include <QtGui/qopengl.h>
#include <QtGui/qopenglfunctions.h>
+#include <QtGui/qoffscreensurface.h>
#include "qopengldebug.h"
@@ -1287,8 +1288,41 @@ void QOpenGLDebugLoggerPrivate::controlDebugMessages(QOpenGLDebugMessage::Source
*/
void QOpenGLDebugLoggerPrivate::_q_contextAboutToBeDestroyed()
{
+ Q_ASSERT(context);
+
+ // Re-make our context current somehow, otherwise stopLogging will fail.
+
+ // Save the current context and its surface in case we need to set them back
+ QOpenGLContext *currentContext = QOpenGLContext::currentContext();
+ QSurface *currentSurface = 0;
+
+ QScopedPointer<QOffscreenSurface> offscreenSurface;
+
+ if (context != currentContext) {
+ // Make our old context current on a temporary surface
+ if (currentContext)
+ currentSurface = currentContext->surface();
+
+ offscreenSurface.reset(new QOffscreenSurface);
+ offscreenSurface->setFormat(context->format());
+ offscreenSurface->create();
+ if (!context->makeCurrent(offscreenSurface.data()))
+ qWarning("QOpenGLDebugLoggerPrivate::_q_contextAboutToBeDestroyed(): could not make the owning GL context current for cleanup");
+ }
+
Q_Q(QOpenGLDebugLogger);
q->stopLogging();
+
+ if (offscreenSurface) {
+ // We did change the current context: set it back
+ if (currentContext)
+ currentContext->makeCurrent(currentSurface);
+ else
+ context->doneCurrent();
+ }
+
+ QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed()));
+ context = 0;
initialized = false;
}
@@ -1494,6 +1528,12 @@ void QOpenGLDebugLogger::stopLogging()
if (!d->isLogging)
return;
+ QOpenGLContext *currentContext = QOpenGLContext::currentContext();
+ if (!currentContext || currentContext != d->context) {
+ qWarning("QOpenGLDebugLogger::stopLogging(): attempting to stop logging with the wrong OpenGL context current");
+ return;
+ }
+
d->isLogging = false;
d->glDebugMessageCallback(d->oldDebugCallbackFunction, d->oldDebugCallbackParameter);