Revert "qt4: Updated to v4.7.3"
[openembedded.git] / recipes / qt4 / qt-4.6.0 / 0946-Fix-WA_TranslucentBackground-for-QGLWidgets-on-X11-E.patch
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
5
6 Also check for existing QEglContext before creating a new one and
7 leaking a context.
8
9 Reviewed-by: TrustMe
10 ---
11  src/opengl/qgl_x11egl.cpp |  118 ++++++++++++++++++++++++++++-----------------
12  1 files changed, 73 insertions(+), 45 deletions(-)
13
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());
20  }
21  
22 +// Chooses the EGL config and creates the EGL context
23  bool QGLContext::chooseContext(const QGLContext* shareContext)
24  {
25      Q_D(QGLContext);
26 @@ -73,56 +74,74 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
27      int devType = device()->devType();
28  
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;
34 -        d->eglContext = 0;
35 -        return false;
36 -    }
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;
42 +            d->eglContext = 0;
43 +            return false;
44 +        }
45  
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);
51 -
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;
59 -    }
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);
66 +
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);
72 +        }
73  
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;
78 -        d->eglContext = 0;
79 -        return false;
80 -    }
81 +        if (!d->eglContext->chooseConfig(configProps, QEgl::BestPixelFormat)) {
82 +            delete d->eglContext;
83 +            d->eglContext = 0;
84 +            return false;
85 +        }
86 +#else
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;
94 +        }
95  
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;
102 +            d->eglContext = 0;
103 +            return false;
104 +        }
105 +#endif
106  
107 -    // Create a new context for the configuration.
108 -    if (!d->eglContext->createContext
109 -            (shareContext ? shareContext->d_func()->eglContext : 0)) {
110 -        delete d->eglContext;
111 -        d->eglContext = 0;
112 -        return false;
113 -    }
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();
119 +
120 +        // Create a new context for the configuration.
121 +        if (!d->eglContext->createContext
122 +                (shareContext ? shareContext->d_func()->eglContext : 0)) {
123 +            delete d->eglContext;
124 +            d->eglContext = 0;
125 +            return false;
126 +        }
127 +        d->sharing = d->eglContext->isSharing();
128 +        if (d->sharing && shareContext)
129 +            const_cast<QGLContext *>(shareContext)->d_func()->sharing = true;
130  
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());
136  #endif
137 +    }
138 +
139 +    // Inform the higher layers about the actual format properties.
140 +    qt_egl_update_format(*(d->eglContext), d->glFormat);
141  
142      return true;
143  }
144 @@ -160,6 +179,9 @@ bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig conf
145  
146      memset(&vi, 0, sizeof(XVisualInfo));
147  
148 +    EGLint eglConfigColorSize;
149 +    eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &eglConfigColorSize);
150 +
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
155              } else
156  #endif
157              {
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;
163 +                } else
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);
166              }
167              XFree(chosenVisualInfo);
168          }
169 @@ -300,6 +326,8 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext,
170  
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))
176              createFailed = true;
177      }
178 -- 
179 1.6.5
180