1 From 76c415b586991d978d46a888fb40c631513407dc Mon Sep 17 00:00:00 2001
2 From: Tom Cooksey <thomas.cooksey@nokia.com>
3 Date: Fri, 4 Dec 2009 20:48:53 +0100
4 Subject: [PATCH 0946/1244] Fix WA_TranslucentBackground for QGLWidgets on X11/EGL
6 Also check for existing QEglContext before creating a new one and
11 src/opengl/qgl_x11egl.cpp | 118 ++++++++++++++++++++++++++++-----------------
12 1 files changed, 73 insertions(+), 45 deletions(-)
14 diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp
15 index b51c239..a868e83 100644
16 --- a/src/opengl/qgl_x11egl.cpp
17 +++ b/src/opengl/qgl_x11egl.cpp
18 @@ -63,6 +63,7 @@ void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device)
19 props.setPixelFormat(static_cast<QImage *>(device)->format());
22 +// Chooses the EGL config and creates the EGL context
23 bool QGLContext::chooseContext(const QGLContext* shareContext)
26 @@ -73,56 +74,74 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
27 int devType = device()->devType();
29 // Get the display and initialize it.
30 - d->eglContext = new QEglContext();
31 - d->eglContext->setApi(QEgl::OpenGL);
32 - if (!d->eglContext->openDisplay(device())) {
33 - delete d->eglContext;
37 + if (d->eglContext == 0) {
38 + d->eglContext = new QEglContext();
39 + d->eglContext->setApi(QEgl::OpenGL);
40 + if (!d->eglContext->openDisplay(device())) {
41 + delete d->eglContext;
46 - // Construct the configuration we need for this surface.
47 - QEglProperties configProps;
48 - qt_egl_set_format(configProps, devType, d->glFormat);
49 - qt_egl_add_platform_config(configProps, device());
50 - configProps.setRenderableType(QEgl::OpenGL);
52 - QEgl::PixelFormatMatch matchType = QEgl::BestPixelFormat;
53 - if (device()->depth() == 16) {
54 - configProps.setValue(EGL_RED_SIZE, 5);
55 - configProps.setValue(EGL_GREEN_SIZE, 6);
56 - configProps.setValue(EGL_BLUE_SIZE, 5);
57 - configProps.setValue(EGL_ALPHA_SIZE, 0);
58 - matchType = QEgl::ExactPixelFormat;
60 - configProps.setRenderableType(QEgl::OpenGL);
61 + // Construct the configuration we need for this surface.
62 + QEglProperties configProps;
63 + qt_egl_set_format(configProps, devType, d->glFormat);
64 + qt_egl_add_platform_config(configProps, device());
65 + configProps.setRenderableType(QEgl::OpenGL);
67 +#if We_have_an_EGL_library_which_bothers_to_check_EGL_BUFFER_SIZE
68 + if (device()->depth() == 16 && configProps.value(EGL_ALPHA_SIZE) <= 0) {
69 + qDebug("Setting EGL_BUFFER_SIZE to 16");
70 + configProps.setValue(EGL_BUFFER_SIZE, 16);
71 + configProps.setValue(EGL_ALPHA_SIZE, 0);
74 - // Search for a matching configuration, reducing the complexity
75 - // each time until we get something that matches.
76 - if (!d->eglContext->chooseConfig(configProps, matchType)) {
77 - delete d->eglContext;
81 + if (!d->eglContext->chooseConfig(configProps, QEgl::BestPixelFormat)) {
82 + delete d->eglContext;
87 + QEgl::PixelFormatMatch matchType = QEgl::BestPixelFormat;
88 + if ((device()->depth() == 16) && configProps.value(EGL_ALPHA_SIZE) == 0) {
89 + configProps.setValue(EGL_RED_SIZE, 5);
90 + configProps.setValue(EGL_GREEN_SIZE, 6);
91 + configProps.setValue(EGL_BLUE_SIZE, 5);
92 + configProps.setValue(EGL_ALPHA_SIZE, 0);
93 + matchType = QEgl::ExactPixelFormat;
96 - // Inform the higher layers about the actual format properties.
97 - qt_egl_update_format(*(d->eglContext), d->glFormat);
98 + // Search for a matching configuration, reducing the complexity
99 + // each time until we get something that matches.
100 + if (!d->eglContext->chooseConfig(configProps, matchType)) {
101 + delete d->eglContext;
107 - // Create a new context for the configuration.
108 - if (!d->eglContext->createContext
109 - (shareContext ? shareContext->d_func()->eglContext : 0)) {
110 - delete d->eglContext;
114 - d->sharing = d->eglContext->isSharing();
115 - if (d->sharing && shareContext)
116 - const_cast<QGLContext *>(shareContext)->d_func()->sharing = true;
117 +// qDebug("QGLContext::chooseContext() - using EGL config %d:", d->eglContext->config());
118 +// qDebug() << QEglProperties(d->eglContext->config()).toString();
120 + // Create a new context for the configuration.
121 + if (!d->eglContext->createContext
122 + (shareContext ? shareContext->d_func()->eglContext : 0)) {
123 + delete d->eglContext;
127 + d->sharing = d->eglContext->isSharing();
128 + if (d->sharing && shareContext)
129 + const_cast<QGLContext *>(shareContext)->d_func()->sharing = true;
131 #if defined(EGL_VERSION_1_1)
132 - if (d->glFormat.swapInterval() != -1 && devType == QInternal::Widget)
133 - eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval());
134 + if (d->glFormat.swapInterval() != -1 && devType == QInternal::Widget)
135 + eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval());
139 + // Inform the higher layers about the actual format properties.
140 + qt_egl_update_format(*(d->eglContext), d->glFormat);
144 @@ -160,6 +179,9 @@ bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig conf
146 memset(&vi, 0, sizeof(XVisualInfo));
148 + EGLint eglConfigColorSize;
149 + eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &eglConfigColorSize);
151 // Check to see if EGL is suggesting an appropriate visual id:
152 EGLint nativeVisualId;
153 eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId);
154 @@ -189,8 +211,12 @@ bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig conf
158 -// qDebug("Using opaque X Visual ID (%d) provided by EGL", (int)vi.visualid);
159 - vi = *chosenVisualInfo;
160 + if (eglConfigColorSize == chosenVisualInfo->depth) {
161 +// qDebug("Using opaque X Visual ID (%d) provided by EGL", (int)vi.visualid);
162 + vi = *chosenVisualInfo;
164 + qWarning("Warning: EGL suggested using X visual ID %d (%d bpp) for config %d (%d bpp), but the depths do not match!",
165 + nativeVisualId, chosenVisualInfo->depth, (int)config, eglConfigColorSize);
167 XFree(chosenVisualInfo);
169 @@ -300,6 +326,8 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext,
171 bool createFailed = false;
172 if (!d->glcx->isValid()) {
173 + // Create the QGLContext here, which in turn chooses the EGL config
174 + // and creates the EGL context:
175 if (!d->glcx->create(shareContext ? shareContext : oldcx))