diff options
author | Tom Cooksey <thomas.cooksey@nokia.com> | 2010-03-05 16:29:53 (GMT) |
---|---|---|
committer | Tom Cooksey <thomas.cooksey@nokia.com> | 2010-03-05 16:31:28 (GMT) |
commit | 7d587efef35b3adbb3433a4baec1c5ee7105cf0b (patch) | |
tree | 9a91ea4dd498684fb5236512f427d2dc2ea03b47 /src/opengl/qpixmapdata_x11gl_egl.cpp | |
parent | ee07fff45d49e69d9a4f4474861a219af8d557f2 (diff) | |
download | Qt-7d587efef35b3adbb3433a4baec1c5ee7105cf0b.zip Qt-7d587efef35b3adbb3433a4baec1c5ee7105cf0b.tar.gz Qt-7d587efef35b3adbb3433a4baec1c5ee7105cf0b.tar.bz2 |
Port QX11GLPixmapData & QX11GLWindowSurface to new QEgl API
It's still just as buggy, but at least it allows us to remove a lot
of crud from qgl_x11egl.cpp.
Reviewed-By: TrustMe
Diffstat (limited to 'src/opengl/qpixmapdata_x11gl_egl.cpp')
-rw-r--r-- | src/opengl/qpixmapdata_x11gl_egl.cpp | 138 |
1 files changed, 56 insertions, 82 deletions
diff --git a/src/opengl/qpixmapdata_x11gl_egl.cpp b/src/opengl/qpixmapdata_x11gl_egl.cpp index 811e554..34915f5 100644 --- a/src/opengl/qpixmapdata_x11gl_egl.cpp +++ b/src/opengl/qpixmapdata_x11gl_egl.cpp @@ -58,13 +58,12 @@ QT_BEGIN_NAMESPACE -extern EGLConfig qt_chooseEGLConfigForPixmap(bool hasAlpha, bool readOnly); // in qgl_x11egl.cpp -extern bool qt_createEGLSurfaceForPixmap(QPixmapData* pmd, bool readOnly); // in qgl_x11egl.cpp // On 16bpp systems, RGB & ARGB pixmaps are different bit-depths and therefore need // different contexts: -static EGLContext qPixmapARGBSharedEglContext = EGL_NO_CONTEXT; -static EGLContext qPixmapRGBSharedEglContext = EGL_NO_CONTEXT; +QEglContext* QX11GLPixmapData::rgbContext = 0; +QEglContext* QX11GLPixmapData::argbContext = 0; + bool QX11GLPixmapData::hasX11GLPixmaps() { @@ -76,68 +75,64 @@ bool QX11GLPixmapData::hasX11GLPixmaps() checkedForX11Pixmaps = true; - QX11PixmapData *argbPixmapData = 0; - QX11PixmapData *rgbPixmapData = 0; do { if (qgetenv("QT_USE_X11GL_PIXMAPS").isEmpty()) break; - // Check we actually have EGL configs which support pixmaps - EGLConfig argbConfig = qt_chooseEGLConfigForPixmap(true, false); - EGLConfig rgbConfig = qt_chooseEGLConfigForPixmap(false, false); + EGLConfig rgbConfig = QEgl::defaultConfig(QInternal::Pixmap, QEgl::OpenGL, QEgl::Renderable); + EGLConfig argbConfig = QEgl::defaultConfig(QInternal::Pixmap, QEgl::OpenGL, + QEgl::Renderable | QEgl::Translucent); + + if (!rgbContext) { + rgbContext = new QEglContext; + rgbContext->setConfig(rgbConfig); + rgbContext->createContext(); + } - if (argbConfig == 0 || rgbConfig == 0) + if (!rgbContext->isValid()) break; - // Create the shared contexts: - eglBindAPI(EGL_OPENGL_ES_API); - EGLint contextAttribs[] = { -#if defined(QT_OPENGL_ES_2) - EGL_CONTEXT_CLIENT_VERSION, 2, -#endif - EGL_NONE - }; - qPixmapARGBSharedEglContext = eglCreateContext(QEgl::display(), - argbConfig, 0, contextAttribs); - - if (argbConfig == rgbConfig) { - // If the configs are the same, we can re-use the same context. - qPixmapRGBSharedEglContext = qPixmapARGBSharedEglContext; - } else { - qPixmapRGBSharedEglContext = eglCreateContext(QEgl::display(), - rgbConfig, 0, contextAttribs); - } + // If the configs are the same, use the same egl contexts: + if (rgbConfig == argbConfig) + argbContext = rgbContext; - argbPixmapData = new QX11PixmapData(QPixmapData::PixmapType); - argbPixmapData->resize(100, 100); - argbPixmapData->fill(Qt::transparent); // Force ARGB + if (!argbContext) { + argbContext = new QEglContext; + argbContext->setConfig(argbConfig); + argbContext->createContext(); + } - if (!qt_createEGLSurfaceForPixmap(argbPixmapData, false)) + if (!argbContext->isValid()) break; - haveX11Pixmaps = eglMakeCurrent(QEgl::display(), - (EGLSurface)argbPixmapData->gl_surface, - (EGLSurface)argbPixmapData->gl_surface, - qPixmapARGBSharedEglContext); + { + QX11PixmapData *argbPixmapData = new QX11PixmapData(QPixmapData::PixmapType); + argbPixmapData->resize(100, 100); + argbPixmapData->fill(Qt::transparent); // Force ARGB + QPixmap argbPixmap(argbPixmapData); + EGLSurface argbPixmapSurface = QEgl::createSurface(&argbPixmap, argbConfig); + haveX11Pixmaps = argbContext->makeCurrent(argbPixmapSurface); + argbContext->doneCurrent(); + eglDestroySurface(QEgl::display(), argbPixmapSurface); + } + if (!haveX11Pixmaps) { - qWarning() << "Unable to make pixmap config current:" << QEgl::errorString(); + qWarning() << "Unable to make pixmap surface current:" << QEgl::errorString(); break; } - // If the ARGB & RGB configs are the same, we don't need to check RGB too - if (haveX11Pixmaps && (argbConfig != rgbConfig)) { - rgbPixmapData = new QX11PixmapData(QPixmapData::PixmapType); + // If the ARGB & RGB configs are different, check RGB too: + if (argbConfig != rgbConfig) { + QX11PixmapData *rgbPixmapData = new QX11PixmapData(QPixmapData::PixmapType); rgbPixmapData->resize(100, 100); rgbPixmapData->fill(Qt::red); - // Try to actually create an EGL pixmap surface - if (!qt_createEGLSurfaceForPixmap(rgbPixmapData, false)) - break; + QPixmap rgbPixmap(rgbPixmapData); + EGLSurface rgbPixmapSurface = QEgl::createSurface(&rgbPixmap, rgbConfig); + haveX11Pixmaps = rgbContext->makeCurrent(rgbPixmapSurface); + rgbContext->doneCurrent(); + eglDestroySurface(QEgl::display(), rgbPixmapSurface); - haveX11Pixmaps = eglMakeCurrent(QEgl::display(), - (EGLSurface)rgbPixmapData->gl_surface, - (EGLSurface)rgbPixmapData->gl_surface, - qPixmapRGBSharedEglContext); if (!haveX11Pixmaps) { qWarning() << "Unable to make pixmap config current:" << QEgl::errorString(); break; @@ -145,36 +140,15 @@ bool QX11GLPixmapData::hasX11GLPixmaps() } } while (0); - if (qPixmapARGBSharedEglContext || qPixmapRGBSharedEglContext) { - eglMakeCurrent(QEgl::display(), - EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - } - - if (argbPixmapData) { - if (argbPixmapData->gl_surface) - QGLContextPrivate::destroyGlSurfaceForPixmap(argbPixmapData); - delete argbPixmapData; - argbPixmapData = 0; - } - if (rgbPixmapData) { - if (rgbPixmapData->gl_surface) - QGLContextPrivate::destroyGlSurfaceForPixmap(rgbPixmapData); - delete rgbPixmapData; - rgbPixmapData = 0; - } - if (!haveX11Pixmaps) { - // Clean up the context(s) if we can't use X11GL pixmaps - if (qPixmapARGBSharedEglContext != EGL_NO_CONTEXT) - eglDestroyContext(QEgl::display(), qPixmapARGBSharedEglContext); - - if (qPixmapRGBSharedEglContext != qPixmapARGBSharedEglContext && - qPixmapRGBSharedEglContext != EGL_NO_CONTEXT) - { - eglDestroyContext(QEgl::display(), qPixmapRGBSharedEglContext); + if (argbContext && (argbContext != rgbContext)) { + delete argbContext; + argbContext = 0; + } + if (rgbContext) { + delete rgbContext; + rgbContext = 0; } - qPixmapRGBSharedEglContext = EGL_NO_CONTEXT; - qPixmapARGBSharedEglContext = EGL_NO_CONTEXT; } if (haveX11Pixmaps) @@ -209,11 +183,8 @@ QPaintEngine* QX11GLPixmapData::paintEngine() const // We need to create the context before beginPaint - do it here: if (!ctx) { ctx = new QGLContext(glFormat()); - if (ctx->d_func()->eglContext == 0) - ctx->d_func()->eglContext = new QEglContext(); - ctx->d_func()->eglContext->setApi(QEgl::OpenGL); - ctx->d_func()->eglContext->setContext(hasAlphaChannel() ? qPixmapARGBSharedEglContext - : qPixmapRGBSharedEglContext); + Q_ASSERT(ctx->d_func()->eglContext == 0); + ctx->d_func()->eglContext = hasAlphaChannel() ? argbContext : rgbContext; } QPaintEngine* engine; @@ -256,10 +227,13 @@ QPaintEngine* QX11GLPixmapData::paintEngine() const void QX11GLPixmapData::beginPaint() { // qDebug("QX11GLPixmapData::beginPaint()"); + // TODO: Check to see if the surface is renderable if ((EGLSurface)gl_surface == EGL_NO_SURFACE) { - qt_createEGLSurfaceForPixmap(this, false); + 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; - ctx->d_func()->valid = true; // ;-) + ctx->d_func()->valid = true; } QGLPaintDevice::beginPaint(); } |