From 4737daef1c8d7a181117d6482f5b57cfc433e050 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Mon, 8 Mar 2010 15:26:33 +0100 Subject: Handle EGLSurfaces better, including more error detection Note: This changes QX11PixmapData::gl_surface to a void* to enable build on 64-bit systems where EGLSurface is a pointer. Reviewed-By: TrustMe --- src/gui/egl/qegl.cpp | 7 ++++++- src/gui/egl/qegl_x11.cpp | 2 +- src/gui/image/qpixmap_x11_p.h | 2 +- src/opengl/qgl_x11.cpp | 2 +- src/opengl/qgl_x11egl.cpp | 8 ++++---- src/opengl/qpixmapdata_x11gl_egl.cpp | 10 ++++++++-- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/gui/egl/qegl.cpp b/src/gui/egl/qegl.cpp index 485bfbf..6e0331f 100644 --- a/src/gui/egl/qegl.cpp +++ b/src/gui/egl/qegl.cpp @@ -392,6 +392,11 @@ bool QEglContext::makeCurrent(EGLSurface surface) return false; } + if (surface == EGL_NO_SURFACE) { + qWarning() << "QEglContext::makeCurrent(): Cannot make invalid surface current"; + return false; + } + // If lazyDoneCurrent() was called on the surface, then we may be able // to assume that it is still current within the thread. if (surface == currentSurface && currentContext(apiType) == this) { @@ -417,7 +422,7 @@ bool QEglContext::makeCurrent(EGLSurface surface) bool ok = eglMakeCurrent(QEgl::display(), surface, surface, ctx); if (!ok) - qWarning() << "QEglContext::makeCurrent():" << QEgl::errorString(); + qWarning() << "QEglContext::makeCurrent(" << surface << "):" << QEgl::errorString(); return ok; } diff --git a/src/gui/egl/qegl_x11.cpp b/src/gui/egl/qegl_x11.cpp index 53c4711..91423c8 100644 --- a/src/gui/egl/qegl_x11.cpp +++ b/src/gui/egl/qegl_x11.cpp @@ -408,7 +408,7 @@ EGLSurface QEgl::createSurface(QPaintDevice *device, EGLConfig config, const QEg EGLSurface surf = eglCreatePixmapSurface(QEgl::display(), config, (EGLNativePixmapType) x11PixmapData->handle(), surfaceAttribs.properties()); - x11PixmapData->gl_surface = (Qt::HANDLE)surf; + x11PixmapData->gl_surface = (void*)surf; QImagePixmapCleanupHooks::enableCleanupHooks(x11PixmapData); return surf; } diff --git a/src/gui/image/qpixmap_x11_p.h b/src/gui/image/qpixmap_x11_p.h index 521a612..7575838 100644 --- a/src/gui/image/qpixmap_x11_p.h +++ b/src/gui/image/qpixmap_x11_p.h @@ -94,7 +94,7 @@ public: static Qt::HANDLE createBitmapFromImage(const QImage &image); - Qt::HANDLE gl_surface; + void* gl_surface; #ifndef QT_NO_XRENDER void convertToARGB32(bool preserveContents = true); #endif diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp index f0b06ef5..4fa1467 100644 --- a/src/opengl/qgl_x11.cpp +++ b/src/opengl/qgl_x11.cpp @@ -1753,7 +1753,7 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData *pmd, con if (!glxPixmap) return 0; - pixmapData->gl_surface = (Qt::HANDLE)glxPixmap; + pixmapData->gl_surface = (void*)glxPixmap; // Make sure the cleanup hook gets called so we can delete the glx pixmap QImagePixmapCleanupHooks::enableCleanupHooks(pixmapData); diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index fdcc412..81eb35c 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -243,7 +243,7 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) if (x11PixmapData->gl_surface) eglDestroySurface(d->eglContext->display(), (EGLSurface)x11PixmapData->gl_surface); - x11PixmapData->gl_surface = (Qt::HANDLE)QEgl::createSurface(device(), d->eglContext->config()); + x11PixmapData->gl_surface = (void*)QEgl::createSurface(device(), d->eglContext->config()); } return true; @@ -404,8 +404,8 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, cons hasAlpha ? QEgl::Translucent : QEgl::NoOptions); QPixmap tmpPixmap(pixmapData); //### - pixmapData->gl_surface = (Qt::HANDLE)QEgl::createSurface(&tmpPixmap, config); - if (pixmapData->gl_surface == (Qt::HANDLE)EGL_NO_SURFACE) { + pixmapData->gl_surface = (void*)QEgl::createSurface(&tmpPixmap, config); + if (pixmapData->gl_surface == (void*)EGL_NO_SURFACE) { haveTFP = false; return 0; } @@ -423,7 +423,7 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, cons if (success == EGL_FALSE) { qWarning() << "eglBindTexImage() failed:" << QEgl::errorString(); eglDestroySurface(eglContext->display(), (EGLSurface)pixmapData->gl_surface); - pixmapData->gl_surface = (Qt::HANDLE)EGL_NO_SURFACE; + pixmapData->gl_surface = (void*)EGL_NO_SURFACE; haveTFP = false; return 0; } diff --git a/src/opengl/qpixmapdata_x11gl_egl.cpp b/src/opengl/qpixmapdata_x11gl_egl.cpp index b6c33f2..797fe6b 100644 --- a/src/opengl/qpixmapdata_x11gl_egl.cpp +++ b/src/opengl/qpixmapdata_x11gl_egl.cpp @@ -235,8 +235,14 @@ void QX11GLPixmapData::beginPaint() if ((EGLSurface)gl_surface == EGL_NO_SURFACE) { QPixmap tmpPixmap(this); EGLConfig cfg = ctx->d_func()->eglContext->config(); - gl_surface = (Qt::HANDLE)QEgl::createSurface(&tmpPixmap, cfg); - ctx->d_func()->eglSurface = (EGLSurface)gl_surface; + + EGLSurface surface = QEgl::createSurface(&tmpPixmap, cfg); + if (surface == EGL_NO_SURFACE) { + qWarning() << "Error creating EGL surface for pixmap:" << QEgl::errorString(); + return; + } + gl_surface = (void*)surface; + ctx->d_func()->eglSurface = surface; ctx->d_func()->valid = true; } QGLPaintDevice::beginPaint(); -- cgit v0.12