From fc0e0198c5e7ef75d1650bca39a5f06ebddfb932 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Thu, 11 Mar 2010 15:44:08 +0100 Subject: Delete the QGLContext in ~QX11GLPixmapData This also includes changes which allow QGLContext to not own it's own QEglContext. With X11GL, the QEglContext gets reused by multiple QGLContexts so it is important QGLContext doesn't delete it. Reviewed-By: TrustMe --- src/gui/egl/qegl.cpp | 2 +- src/opengl/qgl.cpp | 1 + src/opengl/qgl_egl.cpp | 5 +++-- src/opengl/qgl_p.h | 1 + src/opengl/qgl_qws.cpp | 1 + src/opengl/qgl_wince.cpp | 1 + src/opengl/qgl_x11egl.cpp | 1 + src/opengl/qpixmapdata_x11gl_egl.cpp | 3 +++ 8 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gui/egl/qegl.cpp b/src/gui/egl/qegl.cpp index 6e0331f..b870523 100644 --- a/src/gui/egl/qegl.cpp +++ b/src/gui/egl/qegl.cpp @@ -60,7 +60,7 @@ static QEglContext * volatile currentVGContext = 0; QEglContext::QEglContext() : apiType(QEgl::OpenGL) , ctx(EGL_NO_CONTEXT) - , cfg(0) + , cfg(QEGL_NO_CONFIG) , currentSurface(EGL_NO_SURFACE) , current(false) , ownsContext(true) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index c6ecef6..58ac642 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1583,6 +1583,7 @@ void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) vi = 0; #endif #if defined(QT_OPENGL_ES) + ownsEglContext = false; eglContext = 0; eglSurface = EGL_NO_SURFACE; #endif diff --git a/src/opengl/qgl_egl.cpp b/src/opengl/qgl_egl.cpp index c08d6fd..aa8d2bc 100644 --- a/src/opengl/qgl_egl.cpp +++ b/src/opengl/qgl_egl.cpp @@ -164,10 +164,11 @@ void QGLContext::reset() return; d->cleanup(); doneCurrent(); - if (d->eglContext) { + if (d->eglContext && d->ownsEglContext) { d->destroyEglSurfaceForDevice(); delete d->eglContext; } + d->ownsEglContext = false; d->eglContext = 0; d->eglSurface = EGL_NO_SURFACE; d->crWin = false; @@ -215,7 +216,7 @@ void QGLContextPrivate::destroyEglSurfaceForDevice() #ifdef Q_WS_X11 // Make sure we don't call eglDestroySurface on a surface which // was created for a different winId: - if (paintDevice->devType() == QInternal::Widget) { + if (paintDevice && paintDevice->devType() == QInternal::Widget) { QGLWidget* w = static_cast(paintDevice); if (w->d_func()->eglSurfaceWindowId == w->winId()) diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 5e524a7..f66031a 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -347,6 +347,7 @@ public: HDC hbitmap_hdc; #endif #if defined(QT_OPENGL_ES) + bool ownsEglContext; QEglContext *eglContext; EGLSurface eglSurface; void destroyEglSurfaceForDevice(); diff --git a/src/opengl/qgl_qws.cpp b/src/opengl/qgl_qws.cpp index 96b2454..38c3774 100644 --- a/src/opengl/qgl_qws.cpp +++ b/src/opengl/qgl_qws.cpp @@ -182,6 +182,7 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) // Get the display and initialize it. d->eglContext = new QEglContext(); + d->ownsEglContext = true; d->eglContext->setApi(QEgl::OpenGL); // Construct the configuration we need for this surface. diff --git a/src/opengl/qgl_wince.cpp b/src/opengl/qgl_wince.cpp index fefcca2..47a19b5 100644 --- a/src/opengl/qgl_wince.cpp +++ b/src/opengl/qgl_wince.cpp @@ -145,6 +145,7 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) // Get the display and initialize it. d->eglContext = new QEglContext(); + d->ownsEglContext = true; d->eglContext->setApi(QEgl::OpenGL); // Construct the configuration we need for this surface. diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index fe87c65..0954e69 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -182,6 +182,7 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) // Only create the eglContext if we don't already have one: if (d->eglContext == 0) { d->eglContext = new QEglContext(); + d->ownsEglContext = true; d->eglContext->setApi(QEgl::OpenGL); // If the device is a widget with WA_TranslucentBackground set, make sure the glFormat diff --git a/src/opengl/qpixmapdata_x11gl_egl.cpp b/src/opengl/qpixmapdata_x11gl_egl.cpp index d7fae16..a01eec4 100644 --- a/src/opengl/qpixmapdata_x11gl_egl.cpp +++ b/src/opengl/qpixmapdata_x11gl_egl.cpp @@ -181,6 +181,8 @@ QX11GLPixmapData::QX11GLPixmapData() QX11GLPixmapData::~QX11GLPixmapData() { + if (ctx) + delete ctx; } #if !defined(QT_OPENGL_ES_1) @@ -245,6 +247,7 @@ void QX11GLPixmapData::beginPaint() if ((EGLSurface)gl_surface == EGL_NO_SURFACE) { QPixmap tmpPixmap(this); EGLConfig cfg = ctx->d_func()->eglContext->config(); + Q_ASSERT(cfg != QEGL_NO_CONFIG); EGLSurface surface = QEgl::createSurface(&tmpPixmap, cfg); if (surface == EGL_NO_SURFACE) { -- cgit v0.12