diff options
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/qgl_egl.cpp | 97 | ||||
-rw-r--r-- | src/opengl/qgl_egl_p.h | 6 | ||||
-rw-r--r-- | src/opengl/qgl_p.h | 1 | ||||
-rw-r--r-- | src/opengl/qgl_qws.cpp | 20 | ||||
-rw-r--r-- | src/opengl/qgl_wince.cpp | 18 | ||||
-rw-r--r-- | src/opengl/qgl_x11egl.cpp | 354 | ||||
-rw-r--r-- | src/opengl/qglpixelbuffer.h | 1 | ||||
-rw-r--r-- | src/opengl/qglpixelbuffer_egl.cpp | 10 | ||||
-rw-r--r-- | src/opengl/qpixmapdata_x11gl_egl.cpp | 21 | ||||
-rw-r--r-- | src/opengl/qwindowsurface_gl.cpp | 14 |
10 files changed, 165 insertions, 377 deletions
diff --git a/src/opengl/qgl_egl.cpp b/src/opengl/qgl_egl.cpp index 3addea1..7bfcf27 100644 --- a/src/opengl/qgl_egl.cpp +++ b/src/opengl/qgl_egl.cpp @@ -40,49 +40,51 @@ ****************************************************************************/ #include <QtOpenGL/qgl.h> +#include <QtOpenGL/qglpixelbuffer.h> #include "qgl_p.h" #include "qgl_egl_p.h" +#include "qglpixelbuffer_p.h" + +#ifdef Q_WS_X11 +#include <QtGui/private/qpixmap_x11_p.h> +#endif QT_BEGIN_NAMESPACE -// Set device configuration attributes from a QGLFormat instance. -void qt_egl_set_format(QEglProperties& props, int deviceType, const QGLFormat& f) +void qt_eglproperties_set_glformat(QEglProperties& eglProperties, const QGLFormat& glFormat) { - if (deviceType == QInternal::Pixmap || deviceType == QInternal::Image) - props.setValue(EGL_SURFACE_TYPE, EGL_PIXMAP_BIT); - else if (deviceType == QInternal::Pbuffer) - props.setValue(EGL_SURFACE_TYPE, EGL_PBUFFER_BIT); - else - props.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT); - - // Set the pixel format to that contained in the QGLFormat - // if the system hasn't already chosen a fixed format to - // match the pixmap, widget, etc. - if (props.value(EGL_RED_SIZE) == 0 || f.redBufferSize() != -1) - props.setValue(EGL_RED_SIZE, f.redBufferSize() == -1 ? 1 : f.redBufferSize()); - if (props.value(EGL_GREEN_SIZE) == 0 || f.greenBufferSize() != -1) - props.setValue(EGL_GREEN_SIZE, f.greenBufferSize() == -1 ? 1 : f.greenBufferSize()); - if (props.value(EGL_BLUE_SIZE) == 0 || f.blueBufferSize() != -1) - props.setValue(EGL_BLUE_SIZE, f.blueBufferSize() == -1 ? 1 : f.blueBufferSize()); - if (f.alpha()) { - if (props.value(EGL_ALPHA_SIZE) == 0 || f.alphaBufferSize() != -1) - props.setValue(EGL_ALPHA_SIZE, f.alphaBufferSize() == -1 ? 1 : f.alphaBufferSize()); + // NOTE: QGLFormat uses a magic value of -1 to indicate "don't care", even when a buffer of that + // type has been requested. + if (glFormat.depth()) { + int depthSize = glFormat.depthBufferSize(); + eglProperties.setValue(EGL_DEPTH_SIZE, depthSize == -1 ? 1 : depthSize); } - - if (f.depth()) - props.setValue(EGL_DEPTH_SIZE, f.depthBufferSize() == -1 ? 1 : f.depthBufferSize()); - if (f.stencil()) - props.setValue(EGL_STENCIL_SIZE, f.stencilBufferSize() == -1 ? 1 : f.stencilBufferSize()); - if (f.sampleBuffers()) { - props.setValue(EGL_SAMPLE_BUFFERS, 1); - props.setValue(EGL_SAMPLES, f.samples() == -1 ? 1 : f.samples()); - } else { - props.setValue(EGL_SAMPLE_BUFFERS, 0); + if (glFormat.stencil()) { + int stencilSize = glFormat.stencilBufferSize(); + eglProperties.setValue(EGL_STENCIL_SIZE, stencilSize == -1 ? 1 : stencilSize); + } + if (glFormat.sampleBuffers()) { + int sampleCount = glFormat.samples(); + eglProperties.setValue(EGL_SAMPLES, sampleCount == -1 ? 1 : sampleCount); + eglProperties.setValue(EGL_SAMPLE_BUFFERS, 1); } - if (deviceType == QInternal::Widget) - props.setValue(EGL_LEVEL, f.plane()); + if (glFormat.alpha()) { + int alphaSize = glFormat.alphaBufferSize(); + eglProperties.setValue(EGL_ALPHA_SIZE, alphaSize == -1 ? 1 : alphaSize); + } + + int redSize = glFormat.redBufferSize(); + int greenSize = glFormat.greenBufferSize(); + int blueSize = glFormat.blueBufferSize(); + int alphaSize = glFormat.alphaBufferSize(); + + eglProperties.setValue(EGL_RED_SIZE, redSize > 0 ? redSize : 1); + eglProperties.setValue(EGL_GREEN_SIZE, greenSize > 0 ? greenSize : 1); + eglProperties.setValue(EGL_BLUE_SIZE, blueSize > 0 ? blueSize : 1); + eglProperties.setValue(EGL_ALPHA_SIZE, alphaSize > 0 ? alphaSize : 0); } + // Updates "format" with the parameters of the selected configuration. void qt_egl_update_format(const QEglContext& context, QGLFormat& format) { @@ -126,7 +128,7 @@ void qt_egl_update_format(const QEglContext& context, QGLFormat& format) // Clear the EGL error state because some of the above may // have errored out because the attribute is not applicable // to the surface type. Such errors don't matter. - context.clearError(); + QEgl::clearError(); } bool QGLFormat::hasOpenGL() @@ -158,12 +160,12 @@ void QGLContext::reset() void QGLContext::makeCurrent() { Q_D(QGLContext); - if (!d->valid || !d->eglContext || d->eglSurface == EGL_NO_SURFACE) { + if (!d->valid || !d->eglContext || d->eglSurfaceForDevice() == EGL_NO_SURFACE) { qWarning("QGLContext::makeCurrent(): Cannot make invalid context current"); return; } - if (d->eglContext->makeCurrent(d->eglSurface)) + if (d->eglContext->makeCurrent(d->eglSurfaceForDevice())) QGLContextPrivate::setCurrentContext(this); } @@ -183,7 +185,7 @@ void QGLContext::swapBuffers() const if (!d->valid || !d->eglContext) return; - d->eglContext->swapBuffers(d->eglSurface); + d->eglContext->swapBuffers(d->eglSurfaceForDevice()); } void QGLContextPrivate::destroyEglSurfaceForDevice() @@ -206,6 +208,27 @@ void QGLContextPrivate::destroyEglSurfaceForDevice() } } +EGLSurface QGLContextPrivate::eglSurfaceForDevice() const +{ + if (paintDevice->devType() == QInternal::Widget) + return eglSurface; + if (paintDevice->devType() == QInternal::Pixmap) { +#ifdef Q_WS_X11 + QPixmapData *pmd = static_cast<QPixmap*>(paintDevice)->data_ptr().data(); + if (pmd->classId() == QPixmapData::X11Class) { + QX11PixmapData* x11PixmapData = static_cast<QX11PixmapData*>(pmd); + return (EGLSurface)x11PixmapData->gl_surface; + } else +#endif + return eglSurface; + } + if (paintDevice->devType() == QInternal::Pbuffer) { + QGLPixelBuffer* pbuf = static_cast<QGLPixelBuffer*>(paintDevice); + return pbuf->d_func()->pbuf; + } + return EGL_NO_SURFACE; +} + void QGLWidget::setMouseTracking(bool enable) { QWidget::setMouseTracking(enable); diff --git a/src/opengl/qgl_egl_p.h b/src/opengl/qgl_egl_p.h index c503724..6b65227 100644 --- a/src/opengl/qgl_egl_p.h +++ b/src/opengl/qgl_egl_p.h @@ -53,15 +53,15 @@ // We mean it. // -#include <QtGui/private/qegl_p.h> +#include <QtGui/private/qeglcontext_p.h> +#include <QtGui/private/qeglproperties_p.h> QT_BEGIN_NAMESPACE class QGLFormat; -void qt_egl_set_format(QEglProperties& props, int deviceType, const QGLFormat& f); +void qt_eglproperties_set_glformat(QEglProperties& props, const QGLFormat& format); void qt_egl_update_format(const QEglContext& context, QGLFormat& format); -void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device); QT_END_NAMESPACE diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index ecd8b43..b828bea 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -356,6 +356,7 @@ public: QEglContext *eglContext; EGLSurface eglSurface; void destroyEglSurfaceForDevice(); + EGLSurface eglSurfaceForDevice() const; #elif defined(Q_WS_X11) || defined(Q_WS_MAC) void* cx; #endif diff --git a/src/opengl/qgl_qws.cpp b/src/opengl/qgl_qws.cpp index fd17a27..f72f051 100644 --- a/src/opengl/qgl_qws.cpp +++ b/src/opengl/qgl_qws.cpp @@ -119,21 +119,6 @@ bool QGLFormat::hasOpenGLOverlays() return false; } -void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device) -{ - // Find the QGLScreen for this paint device. - QGLScreen *glScreen = glScreenForDevice(device); - if (!glScreen) { - qWarning("QGLContext::chooseContext(): The screen is not a QGLScreen"); - return; - } - int devType = device->devType(); - if (devType == QInternal::Image) - props.setPixelFormat(static_cast<QImage *>(device)->format()); - else - props.setPixelFormat(glScreen->pixelFormat()); -} - static EGLSurface qt_egl_create_surface (QEglContext *context, QPaintDevice *device, const QEglProperties *properties = 0) @@ -201,8 +186,9 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) // Construct the configuration we need for this surface. QEglProperties configProps; - qt_egl_add_platform_config(configProps, device()); - qt_egl_set_format(configProps, devType, d->glFormat); + qt_eglproperties_set_glformat(configProps, d->glFormat); + configProps.setDeviceType(devType); + configProps.setPaintDeviceFormat(device()); configProps.setRenderableType(QEgl::OpenGL); // Search for a matching configuration, reducing the complexity diff --git a/src/opengl/qgl_wince.cpp b/src/opengl/qgl_wince.cpp index f81115c..3bf7f3a 100644 --- a/src/opengl/qgl_wince.cpp +++ b/src/opengl/qgl_wince.cpp @@ -54,7 +54,8 @@ #include <windows.h> -#include <private/qegl_p.h> +#include <private/qeglproperties_p.h> +#include <private/qeglcontext_p.h> #include <private/qgl_egl_p.h> #include <private/qgl_cl_p.h> @@ -121,16 +122,6 @@ QGLTemporaryContext::~QGLTemporaryContext() QGLFormat Win32/WGL-specific code *****************************************************************************/ -void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device) -{ - int devType = device->devType(); - if (devType == QInternal::Image) - props.setPixelFormat(static_cast<QImage *>(device)->format()); - else - props.setPixelFormat(QImage::Format_RGB16); -} - - static bool opengl32dll = false; bool QGLFormat::hasOpenGLOverlays() @@ -158,8 +149,9 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) // Construct the configuration we need for this surface. QEglProperties configProps; - qt_egl_add_platform_config(configProps, device()); - qt_egl_set_format(configProps, devType, d->glFormat); + qt_eglproperties_set_glformat(configProps, d->glFormat); + configProps.setDeviceType(devType); + configProps.setPaintDeviceFormat(device()); configProps.setRenderableType(QEgl::OpenGL); // Search for a matching configuration, reducing the complexity diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index 3d183ee..ba05e72 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -48,14 +48,12 @@ #include "qgl_egl_p.h" #include "qcolormap.h" #include <QDebug> +#include <QPixmap> QT_BEGIN_NAMESPACE -bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig config, - const QX11Info &x11Info, bool useArgbVisual); - /* QGLTemporaryContext implementation */ @@ -79,12 +77,7 @@ QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) d->surface = 0; int screen = 0; - d->display = eglGetDisplay(EGLNativeDisplayType(X11->display)); - - if (!eglInitialize(d->display, NULL, NULL)) { - qWarning("QGLTemporaryContext: Unable to initialize EGL display."); - return; - } + d->display = QEgl::display(); EGLConfig config; int numConfigs = 0; @@ -107,15 +100,7 @@ QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) int numVisuals; EGLint id = 0; - eglGetConfigAttrib(d->display, config, EGL_NATIVE_VISUAL_ID, &id); - if (id == 0) { - // EGL_NATIVE_VISUAL_ID is optional and might not be supported - // on some implementations - we'll have to do it the hard way - QX11Info xinfo; - qt_egl_setup_x11_visual(visualInfo, d->display, config, xinfo, false); - } else { - visualInfo.visualid = id; - } + visualInfo.visualid = QEgl::getCompatibleVisualId(config); vi = XGetVisualInfo(X11->display, VisualIDMask, &visualInfo, &numVisuals); if (!vi || numVisuals < 1) { qWarning("QGLTemporaryContext: Unable to get X11 visual info id."); @@ -170,12 +155,6 @@ bool QGLFormat::hasOpenGLOverlays() return false; } -void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device) -{ - if (device->devType() == QInternal::Image) - props.setPixelFormat(static_cast<QImage *>(device)->format()); -} - // Chooses the EGL config and creates the EGL context bool QGLContext::chooseContext(const QGLContext* shareContext) { @@ -186,54 +165,53 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) int devType = device()->devType(); - // Get the display and initialize it. + QX11PixmapData *x11PixmapData = 0; + if (devType == QInternal::Pixmap) { + QPixmapData *pmd = static_cast<QPixmap*>(device())->data_ptr().data(); + if (pmd->classId() == QPixmapData::X11Class) + x11PixmapData = static_cast<QX11PixmapData*>(pmd); + else { + // TODO: Replace the pixmap's data with a new QX11PixmapData + qWarning("WARNING: Creating a QGLContext on a QPixmap is only supported for X11 pixmap backend"); + return false; + } + } else if ((devType != QInternal::Widget) && (devType != QInternal::Pbuffer)) { + qWarning("WARNING: Creating a QGLContext not supported on device type %d", devType); + return false; + } + + // Only create the eglContext if we don't already have one: if (d->eglContext == 0) { d->eglContext = new QEglContext(); d->eglContext->setApi(QEgl::OpenGL); + // If the device is a widget with WA_TranslucentBackground set, make sure the glFormat + // has the alpha channel option set: + if (devType == QInternal::Widget) { + QWidget* widget = static_cast<QWidget*>(device()); + if (widget->testAttribute(Qt::WA_TranslucentBackground)) + d->glFormat.setAlpha(true); + } + // Construct the configuration we need for this surface. QEglProperties configProps; - qt_egl_set_format(configProps, devType, d->glFormat); - qt_egl_add_platform_config(configProps, device()); + configProps.setDeviceType(devType); configProps.setRenderableType(QEgl::OpenGL); + qt_eglproperties_set_glformat(configProps, d->glFormat); -#if We_have_an_EGL_library_which_bothers_to_check_EGL_BUFFER_SIZE - if (device()->depth() == 16 && configProps.value(EGL_ALPHA_SIZE) <= 0) { - qDebug("Setting EGL_BUFFER_SIZE to 16"); + // Use EGL_BUFFER_SIZE to make sure we prefer a 16-bit config over a 32-bit config + if (device()->depth() == 16 && !d->glFormat.alpha()) configProps.setValue(EGL_BUFFER_SIZE, 16); - configProps.setValue(EGL_ALPHA_SIZE, 0); - } if (!d->eglContext->chooseConfig(configProps, QEgl::BestPixelFormat)) { delete d->eglContext; d->eglContext = 0; return false; } -#else - QEgl::PixelFormatMatch matchType = QEgl::BestPixelFormat; - if ((device()->depth() == 16) && configProps.value(EGL_ALPHA_SIZE) == 0) { - configProps.setValue(EGL_RED_SIZE, 5); - configProps.setValue(EGL_GREEN_SIZE, 6); - configProps.setValue(EGL_BLUE_SIZE, 5); - configProps.setValue(EGL_ALPHA_SIZE, 0); - matchType = QEgl::ExactPixelFormat; - } - - // Search for a matching configuration, reducing the complexity - // each time until we get something that matches. - if (!d->eglContext->chooseConfig(configProps, matchType)) { - delete d->eglContext; - d->eglContext = 0; - return false; - } -#endif - -// qDebug("QGLContext::chooseContext() - using EGL config %d:", d->eglContext->config()); -// qDebug() << QEglProperties(d->eglContext->config()).toString(); // Create a new context for the configuration. - if (!d->eglContext->createContext - (shareContext ? shareContext->d_func()->eglContext : 0)) { + QEglContext* eglSharedContext = shareContext ? shareContext->d_func()->eglContext : 0; + if (!d->eglContext->createContext(eglSharedContext)) { delete d->eglContext; d->eglContext = 0; return false; @@ -241,16 +219,34 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) d->sharing = d->eglContext->isSharing(); if (d->sharing && shareContext) const_cast<QGLContext *>(shareContext)->d_func()->sharing = true; - -#if defined(EGL_VERSION_1_1) - if (d->glFormat.swapInterval() != -1 && devType == QInternal::Widget) - eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval()); -#endif } // Inform the higher layers about the actual format properties. qt_egl_update_format(*(d->eglContext), d->glFormat); + + // Do don't create the EGLSurface for everything. + // QWidget - yes, create the EGLSurface and store it in QGLContextPrivate::eglSurface + // QGLWidget - yes, create the EGLSurface and store it in QGLContextPrivate::eglSurface + // QPixmap - yes, create the EGLSurface but store it in QX11PixmapData::gl_surface + // QGLPixelBuffer - no, it creates the surface itself and stores it in QGLPixelBufferPrivate::pbuf + + if (devType == QInternal::Widget) { + if (d->eglSurface != EGL_NO_SURFACE) + eglDestroySurface(d->eglContext->display(), d->eglSurface); + d->eglSurface = QEgl::createSurface(device(), d->eglContext->config()); + XFlush(X11->display); + setWindowCreated(true); + } + + if (x11PixmapData) { + // TODO: Actually check to see if the existing surface can be re-used + if (x11PixmapData->gl_surface) + eglDestroySurface(d->eglContext->display(), (EGLSurface)x11PixmapData->gl_surface); + + x11PixmapData->gl_surface = (Qt::HANDLE)QEgl::createSurface(device(), d->eglContext->config()); + } + return true; } @@ -281,142 +277,6 @@ void QGLWidget::updateOverlayGL() //handle overlay } -//#define QT_DEBUG_X11_VISUAL_SELECTION 1 - -bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig config, const QX11Info &x11Info, bool useArgbVisual) -{ - bool foundVisualIsArgb = useArgbVisual; - -#ifdef QT_DEBUG_X11_VISUAL_SELECTION - qDebug("qt_egl_setup_x11_visual() - useArgbVisual=%d", useArgbVisual); -#endif - - memset(&vi, 0, sizeof(XVisualInfo)); - - EGLint eglConfigColorSize; - eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &eglConfigColorSize); - - // Check to see if EGL is suggesting an appropriate visual id: - EGLint nativeVisualId; - eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId); - vi.visualid = nativeVisualId; - - if (vi.visualid) { - // EGL has suggested a visual id, so get the rest of the visual info for that id: - XVisualInfo *chosenVisualInfo; - int matchingCount = 0; - chosenVisualInfo = XGetVisualInfo(x11Info.display(), VisualIDMask, &vi, &matchingCount); - if (chosenVisualInfo) { -#if !defined(QT_NO_XRENDER) - if (useArgbVisual) { - // Check to make sure the visual provided by EGL is ARGB - XRenderPictFormat *format; - format = XRenderFindVisualFormat(x11Info.display(), chosenVisualInfo->visual); - if (format->type == PictTypeDirect && format->direct.alphaMask) { -#ifdef QT_DEBUG_X11_VISUAL_SELECTION - qDebug("Using ARGB X Visual ID (%d) provided by EGL", (int)vi.visualid); -#endif - foundVisualIsArgb = true; - vi = *chosenVisualInfo; - } - else { - qWarning("Warning: EGL suggested using X visual ID %d for config %d, but this is not ARGB", - nativeVisualId, (int)config); - vi.visualid = 0; - } - } else -#endif - { - if (eglConfigColorSize == chosenVisualInfo->depth) { -#ifdef QT_DEBUG_X11_VISUAL_SELECTION - qDebug("Using opaque X Visual ID (%d) provided by EGL", (int)vi.visualid); -#endif - vi = *chosenVisualInfo; - } else - qWarning("Warning: EGL suggested using X visual ID %d (%d bpp) for config %d (%d bpp), but the depths do not match!", - nativeVisualId, chosenVisualInfo->depth, (int)config, eglConfigColorSize); - } - XFree(chosenVisualInfo); - } - else { - qWarning("Warning: EGL suggested using X visual ID %d for config %d, but this seems to be invalid!", - nativeVisualId, (int)config); - vi.visualid = 0; - } - } - - // If EGL does not know the visual ID, so try to select an appropriate one ourselves, first - // using XRender if we're supposed to have an alpha, then falling back to XGetVisualInfo - -#if !defined(QT_NO_XRENDER) - if (vi.visualid == 0 && useArgbVisual) { - // Try to use XRender to find an ARGB visual we can use - vi.screen = x11Info.screen(); - vi.depth = 32; //### We might at some point (soon) get ARGB4444 - vi.c_class = TrueColor; - XVisualInfo *matchingVisuals; - int matchingCount = 0; - matchingVisuals = XGetVisualInfo(x11Info.display(), - VisualScreenMask|VisualDepthMask|VisualClassMask, - &vi, &matchingCount); - - for (int i = 0; i < matchingCount; ++i) { - XRenderPictFormat *format; - format = XRenderFindVisualFormat(x11Info.display(), matchingVisuals[i].visual); - if (format->type == PictTypeDirect && format->direct.alphaMask) { - vi = matchingVisuals[i]; - foundVisualIsArgb = true; -#ifdef QT_DEBUG_X11_VISUAL_SELECTION - qDebug("Using X Visual ID (%d) for ARGB visual as provided by XRender", (int)vi.visualid); -#endif - break; - } - } - XFree(matchingVisuals); - } -#endif - - if (vi.visualid == 0) { - EGLint depth; - eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &depth); - int err; - err = XMatchVisualInfo(x11Info.display(), x11Info.screen(), depth, TrueColor, &vi); - if (err == 0) { - qWarning("Warning: Can't find an X visual which matches the EGL config(%d)'s depth (%d)!", - (int)config, depth); - depth = x11Info.depth(); - err = XMatchVisualInfo(x11Info.display(), x11Info.screen(), depth, TrueColor, &vi); - if (err == 0) { - qWarning("Error: Couldn't get any matching X visual!"); - return false; - } else - qWarning(" - Falling back to X11 suggested depth (%d)", depth); - } -#ifdef QT_DEBUG_X11_VISUAL_SELECTION - else - qDebug("Using X Visual ID (%d) for EGL provided depth (%d)", (int)vi.visualid, depth); -#endif - - // Don't try to use ARGB now unless the visual is 32-bit - even then it might stil fail :-( - if (useArgbVisual) - foundVisualIsArgb = vi.depth == 32; //### We might at some point (soon) get ARGB4444 - } - -#ifdef QT_DEBUG_X11_VISUAL_SELECTION - qDebug("Visual Info:"); - qDebug(" bits_per_rgb=%d", vi.bits_per_rgb); - qDebug(" red_mask=0x%x", vi.red_mask); - qDebug(" green_mask=0x%x", vi.green_mask); - qDebug(" blue_mask=0x%x", vi.blue_mask); - qDebug(" colormap_size=%d", vi.colormap_size); - qDebug(" c_class=%d", vi.c_class); - qDebug(" depth=%d", vi.depth); - qDebug(" screen=%d", vi.screen); - qDebug(" visualid=%d", vi.visualid); -#endif - return foundVisualIsArgb; -} - void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, bool deleteOldContext) { Q_D(QGLWidget); @@ -434,20 +294,6 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, QGLContext* oldcx = d->glcx; d->glcx = context; - if (parentWidget()) { - // force creation of delay-created widgets - parentWidget()->winId(); - if (parentWidget()->x11Info().screen() != x11Info().screen()) - d_func()->xinfo = parentWidget()->d_func()->xinfo; - } - - // If the application has set WA_TranslucentBackground and not explicitly set - // the alpha buffer size to zero, modify the format so it have an alpha channel - QGLFormat& fmt = d->glcx->d_func()->glFormat; - const bool tryArgbVisual = testAttribute(Qt::WA_TranslucentBackground) || fmt.alpha(); - if (tryArgbVisual && fmt.alphaBufferSize() == -1) - fmt.setAlphaBufferSize(1); - bool createFailed = false; if (!d->glcx->isValid()) { // Create the QGLContext here, which in turn chooses the EGL config @@ -461,63 +307,8 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, return; } - if (d->glcx->windowCreated() || d->glcx->deviceIsPixmap()) { - if (deleteOldContext) - delete oldcx; - return; - } - - bool visible = isVisible(); - if (visible) - hide(); - - XVisualInfo vi; - QEglContext *eglContext = d->glcx->d_func()->eglContext; - bool usingArgbVisual = qt_egl_setup_x11_visual(vi, eglContext->display(), eglContext->config(), - x11Info(), tryArgbVisual); - - XSetWindowAttributes a; - - Window p = RootWindow(x11Info().display(), x11Info().screen()); - if (parentWidget()) - p = parentWidget()->winId(); - - QColormap colmap = QColormap::instance(vi.screen); - a.background_pixel = colmap.pixel(palette().color(backgroundRole())); - a.border_pixel = colmap.pixel(Qt::black); - - unsigned int valueMask = CWBackPixel|CWBorderPixel; - if (usingArgbVisual) { - a.colormap = XCreateColormap(x11Info().display(), p, vi.visual, AllocNone); - valueMask |= CWColormap; - } - - Window w = XCreateWindow(x11Info().display(), p, x(), y(), width(), height(), - 0, vi.depth, InputOutput, vi.visual, valueMask, &a); - - if (deleteOldContext) - delete oldcx; - oldcx = 0; - - create(w); // Create with the ID of the window we've just created - - - // Create the EGL surface to draw into. - QGLContextPrivate *ctxpriv = d->glcx->d_func(); - ctxpriv->eglSurface = ctxpriv->eglContext->createSurface(this); - if (ctxpriv->eglSurface == EGL_NO_SURFACE) { - delete ctxpriv->eglContext; - ctxpriv->eglContext = 0; - return; - } - - d->eglSurfaceWindowId = w; // Remember the window id we created the surface for - if (visible) - show(); - - XFlush(X11->display); - d->glcx->setWindowCreated(true); + d->eglSurfaceWindowId = winId(); // Remember the window id we created the surface for } void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget* shareWidget) @@ -526,7 +317,7 @@ void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget* shareWidget) initContext(context, shareWidget); - if(q->isValid() && glcx->format().hasOverlay()) { + if (q->isValid() && glcx->format().hasOverlay()) { //no overlay qWarning("QtOpenGL ES doesn't currently support overlays"); } @@ -609,7 +400,7 @@ EGLConfig Q_OPENGL_EXPORT qt_chooseEGLConfigForPixmap(bool hasAlpha, bool readOn EGLint configCount = 0; do { - eglChooseConfig(QEglContext::display(), configAttribs.properties(), targetConfig, 1, &configCount); + eglChooseConfig(QEgl::display(), configAttribs.properties(), targetConfig, 1, &configCount); if (configCount > 0) { // Got one qDebug() << "Found an" << (hasAlpha ? "ARGB" : "RGB") << (readOnly ? "readonly" : "target" ) @@ -648,7 +439,7 @@ bool Q_OPENGL_EXPORT qt_createEGLSurfaceForPixmap(QPixmapData* pmd, bool readOnl pixmapAttribs.setValue(EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB); EGLSurface pixmapSurface; - pixmapSurface = eglCreatePixmapSurface(QEglContext::display(), + pixmapSurface = eglCreatePixmapSurface(QEgl::display(), pixmapConfig, (EGLNativePixmapType) pixmapData->handle(), pixmapAttribs.properties()); @@ -656,7 +447,7 @@ bool Q_OPENGL_EXPORT qt_createEGLSurfaceForPixmap(QPixmapData* pmd, bool readOnl // pixmapSurface, pixmapData->handle()); if (pixmapSurface == EGL_NO_SURFACE) { qWarning() << "Failed to create a pixmap surface using config" << (int)pixmapConfig - << ":" << QEglContext::errorString(eglGetError()); + << ":" << QEgl::errorString(); return false; } @@ -693,8 +484,8 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, cons if (!checkedForTFP) { // Check for texture_from_pixmap egl extension checkedForTFP = true; - if (eglContext->hasExtension("EGL_NOKIA_texture_from_pixmap") || - eglContext->hasExtension("EGL_EXT_texture_from_pixmap")) + if (QEgl::hasExtension("EGL_NOKIA_texture_from_pixmap") || + QEgl::hasExtension("EGL_EXT_texture_from_pixmap")) { qDebug("Found texture_from_pixmap EGL extension!"); haveTFP = true; @@ -717,8 +508,13 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, cons } if (pixmapData->gl_surface == 0) { - bool success = qt_createEGLSurfaceForPixmap(pixmapData, true); - if (!success) { + EGLConfig config = QEgl::defaultConfig(QInternal::Pixmap, + QEgl::OpenGL, + 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) { haveTFP = false; return 0; } @@ -734,7 +530,7 @@ QGLTexture *QGLContextPrivate::bindTextureFromNativePixmap(QPixmapData* pd, cons EGLBoolean success; success = eglBindTexImage(eglContext->display(), (EGLSurface)pixmapData->gl_surface, EGL_BACK_BUFFER); if (success == EGL_FALSE) { - qWarning() << "eglBindTexImage() failed:" << eglContext->errorString(eglGetError()); + qWarning() << "eglBindTexImage() failed:" << QEgl::errorString(); eglDestroySurface(eglContext->display(), (EGLSurface)pixmapData->gl_surface); pixmapData->gl_surface = (Qt::HANDLE)EGL_NO_SURFACE; haveTFP = false; @@ -757,10 +553,10 @@ void QGLContextPrivate::destroyGlSurfaceForPixmap(QPixmapData* pmd) QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pmd); if (pixmapData->gl_surface) { EGLBoolean success; - success = eglDestroySurface(QEglContext::display(), (EGLSurface)pixmapData->gl_surface); + success = eglDestroySurface(QEgl::display(), (EGLSurface)pixmapData->gl_surface); if (success == EGL_FALSE) { qWarning() << "destroyGlSurfaceForPixmap() - Error deleting surface: " - << QEglContext::errorString(eglGetError()); + << QEgl::errorString(); } pixmapData->gl_surface = 0; } @@ -772,12 +568,12 @@ void QGLContextPrivate::unbindPixmapFromTexture(QPixmapData* pmd) QX11PixmapData *pixmapData = static_cast<QX11PixmapData*>(pmd); if (pixmapData->gl_surface) { EGLBoolean success; - success = eglReleaseTexImage(QEglContext::display(), + success = eglReleaseTexImage(QEgl::display(), (EGLSurface)pixmapData->gl_surface, EGL_BACK_BUFFER); if (success == EGL_FALSE) { qWarning() << "unbindPixmapFromTexture() - Unable to release bound texture: " - << QEglContext::errorString(eglGetError()); + << QEgl::errorString(); } } } diff --git a/src/opengl/qglpixelbuffer.h b/src/opengl/qglpixelbuffer.h index 3304dd8..d9c7e3e 100644 --- a/src/opengl/qglpixelbuffer.h +++ b/src/opengl/qglpixelbuffer.h @@ -112,6 +112,7 @@ private: friend class QGLWindowSurface; friend class QGLPaintDevice; friend class QGLPBufferGLPaintDevice; + friend class QGLContextPrivate; }; QT_END_NAMESPACE diff --git a/src/opengl/qglpixelbuffer_egl.cpp b/src/opengl/qglpixelbuffer_egl.cpp index 954049d..ee0714f 100644 --- a/src/opengl/qglpixelbuffer_egl.cpp +++ b/src/opengl/qglpixelbuffer_egl.cpp @@ -82,7 +82,8 @@ bool QGLPixelBufferPrivate::init(const QSize &size, const QGLFormat &f, QGLWidge #endif } else { QEglProperties configProps; - qt_egl_set_format(configProps, QInternal::Pbuffer, f); + qt_eglproperties_set_glformat(configProps, f); + configProps.setDeviceType(QInternal::Pbuffer); configProps.setRenderableType(ctx->api()); bool ok = false; #if QGL_RENDER_TEXTURE @@ -137,7 +138,7 @@ bool QGLPixelBufferPrivate::init(const QSize &size, const QGLFormat &f, QGLWidge } #endif if (pbuf == EGL_NO_SURFACE) { - qWarning() << "QGLPixelBufferPrivate::init(): Unable to create EGL pbuffer surface:" << QEglContext::errorString(eglGetError()); + qWarning() << "QGLPixelBufferPrivate::init(): Unable to create EGL pbuffer surface:" << QEgl::errorString(); return false; } @@ -204,11 +205,12 @@ GLuint QGLPixelBuffer::generateDynamicTexture() const bool QGLPixelBuffer::hasOpenGLPbuffers() { // See if we have at least 1 configuration that matches the default format. - EGLDisplay dpy = QEglContext::display(); + EGLDisplay dpy = QEgl::display(); if (dpy == EGL_NO_DISPLAY) return false; QEglProperties configProps; - qt_egl_set_format(configProps, QInternal::Pbuffer, QGLFormat::defaultFormat()); + qt_eglproperties_set_glformat(configProps, QGLFormat::defaultFormat()); + configProps.setDeviceType(QInternal::Pbuffer); configProps.setRenderableType(QEgl::OpenGL); do { EGLConfig cfg = 0; diff --git a/src/opengl/qpixmapdata_x11gl_egl.cpp b/src/opengl/qpixmapdata_x11gl_egl.cpp index 6a1d030..811e554 100644 --- a/src/opengl/qpixmapdata_x11gl_egl.cpp +++ b/src/opengl/qpixmapdata_x11gl_egl.cpp @@ -44,6 +44,7 @@ #include <private/qgl_p.h> #include <private/qegl_p.h> #include <private/qeglproperties_p.h> +#include <private/qeglcontext_p.h> #if !defined(QT_OPENGL_ES_1) #include <private/qpaintengineex_opengl2_p.h> @@ -96,14 +97,14 @@ bool QX11GLPixmapData::hasX11GLPixmaps() #endif EGL_NONE }; - qPixmapARGBSharedEglContext = eglCreateContext(QEglContext::display(), + 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(QEglContext::display(), + qPixmapRGBSharedEglContext = eglCreateContext(QEgl::display(), rgbConfig, 0, contextAttribs); } @@ -114,13 +115,12 @@ bool QX11GLPixmapData::hasX11GLPixmaps() if (!qt_createEGLSurfaceForPixmap(argbPixmapData, false)) break; - haveX11Pixmaps = eglMakeCurrent(QEglContext::display(), + haveX11Pixmaps = eglMakeCurrent(QEgl::display(), (EGLSurface)argbPixmapData->gl_surface, (EGLSurface)argbPixmapData->gl_surface, qPixmapARGBSharedEglContext); if (!haveX11Pixmaps) { - EGLint err = eglGetError(); - qWarning() << "Unable to make pixmap config current:" << err << QEglContext::errorString(err); + qWarning() << "Unable to make pixmap config current:" << QEgl::errorString(); break; } @@ -134,20 +134,19 @@ bool QX11GLPixmapData::hasX11GLPixmaps() if (!qt_createEGLSurfaceForPixmap(rgbPixmapData, false)) break; - haveX11Pixmaps = eglMakeCurrent(QEglContext::display(), + haveX11Pixmaps = eglMakeCurrent(QEgl::display(), (EGLSurface)rgbPixmapData->gl_surface, (EGLSurface)rgbPixmapData->gl_surface, qPixmapRGBSharedEglContext); if (!haveX11Pixmaps) { - EGLint err = eglGetError(); - qWarning() << "Unable to make pixmap config current:" << err << QEglContext::errorString(err); + qWarning() << "Unable to make pixmap config current:" << QEgl::errorString(); break; } } } while (0); if (qPixmapARGBSharedEglContext || qPixmapRGBSharedEglContext) { - eglMakeCurrent(QEglContext::display(), + eglMakeCurrent(QEgl::display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } @@ -167,12 +166,12 @@ bool QX11GLPixmapData::hasX11GLPixmaps() if (!haveX11Pixmaps) { // Clean up the context(s) if we can't use X11GL pixmaps if (qPixmapARGBSharedEglContext != EGL_NO_CONTEXT) - eglDestroyContext(QEglContext::display(), qPixmapARGBSharedEglContext); + eglDestroyContext(QEgl::display(), qPixmapARGBSharedEglContext); if (qPixmapRGBSharedEglContext != qPixmapARGBSharedEglContext && qPixmapRGBSharedEglContext != EGL_NO_CONTEXT) { - eglDestroyContext(QEglContext::display(), qPixmapRGBSharedEglContext); + eglDestroyContext(QEgl::display(), qPixmapRGBSharedEglContext); } qPixmapRGBSharedEglContext = EGL_NO_CONTEXT; qPixmapARGBSharedEglContext = EGL_NO_CONTEXT; diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index 4ac4a3a..ca88de3 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -83,7 +83,7 @@ #endif #ifdef QT_OPENGL_ES -#include <private/qegl_p.h> +#include <private/qeglcontext_p.h> #endif QT_BEGIN_NAMESPACE @@ -353,18 +353,6 @@ void QGLWindowSurface::hijackWindow(QWidget *widget) QGLContext *ctx = new QGLContext(surfaceFormat, widget); ctx->create(qt_gl_share_widget()->context()); -#if defined(Q_WS_X11) && defined(QT_OPENGL_ES) - // Create the EGL surface to draw into. QGLContext::chooseContext() - // does not do this for X11/EGL, but does do it for other platforms. - // This probably belongs in qgl_x11egl.cpp. - QGLContextPrivate *ctxpriv = ctx->d_func(); - ctxpriv->eglSurface = ctxpriv->eglContext->createSurface(widget); - if (ctxpriv->eglSurface == EGL_NO_SURFACE) { - qWarning() << "hijackWindow() could not create EGL surface"; - } - qDebug("QGLWindowSurface - using EGLConfig %d", reinterpret_cast<int>(ctxpriv->eglContext->config())); -#endif - widgetPrivate->extraData()->glContext = ctx; union { QGLContext **ctxPtr; void **voidPtr; }; |