eglfs: fix cleanup when more than one tlw was used

There is nothing guaranteeing there is a context current when the
backingstore dtor is invoked for widget windows that do not contain
render-to-texture widgets. In some cases the eglfs compositor's
context is still current, while in other cases (esp. when having
popups and other top-levels) there is none.

To prevent not releasing the backingstore texture and the incorrect
warning about incorrect context, make the correct context current via
an offscreen surface, when necessary.

Change-Id: Id8257650c1ec8cf96910a4f285b779419c3558a8
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
bb10
Laszlo Agocs 2016-01-26 15:48:19 +01:00 committed by Simon Hausmann
parent 0192ab52e2
commit 48ae2dac07
1 changed files with 18 additions and 1 deletions

View File

@ -34,6 +34,7 @@
#include <QtGui/QOpenGLContext>
#include <QtGui/QWindow>
#include <QtGui/QPainter>
#include <QtGui/QOffscreenSurface>
#include <qpa/qplatformbackingstore.h>
#include <private/qwindow_p.h>
@ -82,13 +83,28 @@ QOpenGLCompositorBackingStore::~QOpenGLCompositorBackingStore()
{
if (m_bsTexture) {
QOpenGLContext *ctx = QOpenGLContext::currentContext();
// With render-to-texture-widgets QWidget makes sure the TLW's shareContext() is
// made current before destroying backingstores. That is however not the case for
// windows with regular widgets only.
QScopedPointer<QOffscreenSurface> tempSurface;
if (!ctx) {
ctx = QOpenGLCompositor::instance()->context();
tempSurface.reset(new QOffscreenSurface);
tempSurface->setFormat(ctx->format());
tempSurface->create();
ctx->makeCurrent(tempSurface.data());
}
if (ctx && m_bsTextureContext && ctx->shareGroup() == m_bsTextureContext->shareGroup())
glDeleteTextures(1, &m_bsTexture);
else
qWarning("QOpenGLCompositorBackingStore: Texture is not valid in the current context");
if (tempSurface)
ctx->doneCurrent();
}
delete m_textures;
delete m_textures; // this does not actually own any GL resources
}
QPaintDevice *QOpenGLCompositorBackingStore::paintDevice()
@ -254,6 +270,7 @@ void QOpenGLCompositorBackingStore::resize(const QSize &size, const QRegion &sta
if (m_bsTexture) {
glDeleteTextures(1, &m_bsTexture);
m_bsTexture = 0;
m_bsTextureContext = Q_NULLPTR;
}
}