From 3ae7c0ca536c82659f401c3bed0370f765de8aee Mon Sep 17 00:00:00 2001
From: Paul Olav Tvete <paul.tvete@nokia.com>
Date: Wed, 10 Mar 2010 10:31:50 +0100
Subject: Don't show resize cursor for fixed-size windows
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Task-number: QTBUG-8144
Reviewed-by: Jørgen Lind
---
 src/gui/embedded/qwsmanager_qws.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/gui/embedded/qwsmanager_qws.cpp b/src/gui/embedded/qwsmanager_qws.cpp
index d6ef148..79076c5 100644
--- a/src/gui/embedded/qwsmanager_qws.cpp
+++ b/src/gui/embedded/qwsmanager_qws.cpp
@@ -267,8 +267,10 @@ void QWSManager::mouseMoveEvent(QMouseEvent *e)
 
 
 #ifndef QT_NO_CURSOR
-    QWSDisplay *qwsd = QApplication::desktop()->qwsDisplay();
-    qwsd->selectCursor(d->managed, regionToShape(d->cachedRegionAt()));
+    if (d->managed->minimumSize() != d->managed->maximumSize()) {
+        QWSDisplay *qwsd = QApplication::desktop()->qwsDisplay();
+        qwsd->selectCursor(d->managed, regionToShape(d->cachedRegionAt()));
+    }
 #endif //QT_NO_CURSOR
 
     if (d->activeRegion)
-- 
cgit v0.12


From 79a83854bcae35c22e02212a775fcbf825c1439d Mon Sep 17 00:00:00 2001
From: Tom Cooksey <thomas.cooksey@nokia.com>
Date: Mon, 8 Mar 2010 15:10:25 +0100
Subject: Make sure pixmap hooks get installed so EGL surfaces are cleaned up

Reviewed-By: TrustMe
---
 src/opengl/qpixmapdata_x11gl_egl.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/opengl/qpixmapdata_x11gl_egl.cpp b/src/opengl/qpixmapdata_x11gl_egl.cpp
index 34915f5..b6c33f2 100644
--- a/src/opengl/qpixmapdata_x11gl_egl.cpp
+++ b/src/opengl/qpixmapdata_x11gl_egl.cpp
@@ -138,6 +138,10 @@ bool QX11GLPixmapData::hasX11GLPixmaps()
                 break;
             }
         }
+
+        // The pixmap surface destruction hooks are installed by QGLTextureCache, so we
+        // must make sure this is instanciated:
+        QGLTextureCache::instance();
     } while (0);
 
     if (!haveX11Pixmaps) {
-- 
cgit v0.12


From 4737daef1c8d7a181117d6482f5b57cfc433e050 Mon Sep 17 00:00:00 2001
From: Tom Cooksey <thomas.cooksey@nokia.com>
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


From b0eeab376fc9f698a899be6dbc4c1fe6cef02982 Mon Sep 17 00:00:00 2001
From: Tom Cooksey <thomas.cooksey@nokia.com>
Date: Wed, 10 Mar 2010 09:28:53 +0100
Subject: Make the EGL contexts in QX11GLPixmapData Q_GLOBAL_STATIC

Still not ideal, but this should do for now.

Reviewed-By: TrustMe
---
 src/opengl/qpixmapdata_x11gl_egl.cpp | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/opengl/qpixmapdata_x11gl_egl.cpp b/src/opengl/qpixmapdata_x11gl_egl.cpp
index 797fe6b..d7fae16 100644
--- a/src/opengl/qpixmapdata_x11gl_egl.cpp
+++ b/src/opengl/qpixmapdata_x11gl_egl.cpp
@@ -61,6 +61,10 @@ QT_BEGIN_NAMESPACE
 
 // On 16bpp systems, RGB & ARGB pixmaps are different bit-depths and therefore need
 // different contexts:
+
+Q_GLOBAL_STATIC(QEglContext, qt_x11gl_rgbContext);
+Q_GLOBAL_STATIC(QEglContext, qt_x11gl_argbContext)
+
 QEglContext* QX11GLPixmapData::rgbContext = 0;
 QEglContext* QX11GLPixmapData::argbContext = 0;
 
@@ -75,6 +79,9 @@ bool QX11GLPixmapData::hasX11GLPixmaps()
 
     checkedForX11Pixmaps = true;
 
+    EGLint rgbConfigId;
+    EGLint argbConfigId;
+
     do {
         if (qgetenv("QT_USE_X11GL_PIXMAPS").isEmpty())
             break;
@@ -83,8 +90,11 @@ bool QX11GLPixmapData::hasX11GLPixmaps()
         EGLConfig argbConfig = QEgl::defaultConfig(QInternal::Pixmap, QEgl::OpenGL,
                                                    QEgl::Renderable | QEgl::Translucent);
 
+        eglGetConfigAttrib(QEgl::display(), rgbConfig, EGL_CONFIG_ID, &rgbConfigId);
+        eglGetConfigAttrib(QEgl::display(), argbConfig, EGL_CONFIG_ID, &argbConfigId);
+
         if (!rgbContext) {
-            rgbContext = new QEglContext;
+            rgbContext = qt_x11gl_rgbContext();
             rgbContext->setConfig(rgbConfig);
             rgbContext->createContext();
         }
@@ -97,7 +107,7 @@ bool QX11GLPixmapData::hasX11GLPixmaps()
             argbContext = rgbContext;
 
         if (!argbContext) {
-            argbContext = new QEglContext;
+            argbContext = qt_x11gl_argbContext();
             argbContext->setConfig(argbConfig);
             argbContext->createContext();
         }
@@ -156,7 +166,7 @@ bool QX11GLPixmapData::hasX11GLPixmaps()
     }
 
     if (haveX11Pixmaps)
-        qDebug("QX11GLPixmapData is supported");
+        qDebug("Using QX11GLPixmapData with EGL config %d for ARGB and config %d for RGB", argbConfigId, rgbConfigId);
     else
         qDebug("QX11GLPixmapData is *NOT* being used");
 
-- 
cgit v0.12


From 620a584c20c1aeb059803dfe246597daaf4f4e04 Mon Sep 17 00:00:00 2001
From: Tom Cooksey <thomas.cooksey@nokia.com>
Date: Wed, 10 Mar 2010 10:16:23 +0100
Subject: Make sure 16-bit EGL configs are chosen over 32-bit configs

We want to make sure 16-bit configs are chosen over 32-bit configs as
they will provide the best performance. The EGL config selection
algorithm is a bit stange in this regard: The selection criteria for
EGL_BUFFER_SIZE is "AtLeast", so we can't use it to discard 32-bit
configs completely from the selection. So it then comes to the
sorting algorithm. The red/green/blue sizes have a sort priority of
3, so they are sorted by first. The sort order is special and
described as "by larger _total_ number of color bits.". So EGL will
put 32-bit configs in the list before the 16-bit configs. However,
the spec also goes on to say "If the requested number of bits in
attrib_list for a particular component is 0, then the number of bits
for that component is not considered". This part of the spec also
seems to imply that setting the red/green/blue bits to zero means
none of the components are considered and EGL disregards the entire
sorting rule. It then looks to the next highest priority rule, which
is EGL_BUFFER_SIZE. Despite the selection criteria being "AtLeast"
for EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit
configs are put in the list before 32-bit configs. So, to make sure
16-bit is preffered over 32-bit, we must set the red/green/blue
sizes to zero. This has an unfortunate consequence that if the
application sets the red/green/blue size to 5/6/5 on the QGLFormat,
they will probably get a 32-bit config, even when there's an RGB565
config avaliable. Oh well.

Reviewed-By: TrustMe
---
 src/opengl/qgl_egl.cpp    | 83 +++++++++++++++++++++++++++++++----------------
 src/opengl/qgl_x11egl.cpp |  4 ---
 2 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/src/opengl/qgl_egl.cpp b/src/opengl/qgl_egl.cpp
index 91b271b..3d146b7 100644
--- a/src/opengl/qgl_egl.cpp
+++ b/src/opengl/qgl_egl.cpp
@@ -53,35 +53,62 @@ QT_BEGIN_NAMESPACE
 
 void qt_eglproperties_set_glformat(QEglProperties& eglProperties, const QGLFormat& glFormat)
 {
-    // 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);
+    int redSize     = glFormat.redBufferSize();
+    int greenSize   = glFormat.greenBufferSize();
+    int blueSize    = glFormat.blueBufferSize();
+    int alphaSize   = glFormat.alphaBufferSize();
+    int depthSize   = glFormat.depthBufferSize();
+    int stencilSize = glFormat.stencilBufferSize();
+    int sampleCount = glFormat.samples();
+
+    // QGLFormat uses a magic value of -1 to indicate "don't care", even when a buffer of that
+    // type has been requested. So we must check QGLFormat's booleans too if size is -1:
+    if (glFormat.alpha() && alphaSize <= 0) {
+        qDebug("QGLFormat::alpha() returned true");
+        alphaSize = 1;
     }
-    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 (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);
+    if (glFormat.depth() && depthSize <= 0)
+        depthSize = 1;
+    if (glFormat.stencil() && stencilSize <= 0)
+        stencilSize = 1;
+    if (glFormat.sampleBuffers() && sampleCount <= 0)
+        sampleCount = 1;
+
+    // We want to make sure 16-bit configs are chosen over 32-bit configs as they will provide
+    // the best performance. The EGL config selection algorithm is a bit stange in this regard:
+    // The selection criteria for EGL_BUFFER_SIZE is "AtLeast", so we can't use it to discard
+    // 32-bit configs completely from the selection. So it then comes to the sorting algorithm.
+    // The red/green/blue sizes have a sort priority of 3, so they are sorted by first. The sort
+    // order is special and described as "by larger _total_ number of color bits.". So EGL will
+    // put 32-bit configs in the list before the 16-bit configs. However, the spec also goes on
+    // to say "If the requested number of bits in attrib_list for a particular component is 0,
+    // then the number of bits for that component is not considered". This part of the spec also
+    // seems to imply that setting the red/green/blue bits to zero means none of the components
+    // are considered and EGL disregards the entire sorting rule. It then looks to the next
+    // highest priority rule, which is EGL_BUFFER_SIZE. Despite the selection criteria being
+    // "AtLeast" for EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit configs are
+    // put in the list before 32-bit configs. So, to make sure 16-bit is preffered over 32-bit,
+    // we must set the red/green/blue sizes to zero. This has an unfortunate consequence that
+    // if the application sets the red/green/blue size to 5/6/5 on the QGLFormat, they will
+    // probably get a 32-bit config, even when there's an RGB565 config avaliable. Oh well.
+
+    // Now normalize the values so -1 becomes 0
+    redSize   = redSize   > 0 ? redSize   : 0;
+    greenSize = greenSize > 0 ? greenSize : 0;
+    blueSize  = blueSize  > 0 ? blueSize  : 0;
+    alphaSize = alphaSize > 0 ? alphaSize : 0;
+    depthSize = depthSize > 0 ? depthSize : 0;
+    stencilSize = stencilSize > 0 ? stencilSize : 0;
+    sampleCount = sampleCount > 0 ? sampleCount : 0;
+
+    eglProperties.setValue(EGL_RED_SIZE,   redSize);
+    eglProperties.setValue(EGL_GREEN_SIZE, greenSize);
+    eglProperties.setValue(EGL_BLUE_SIZE,  blueSize);
+    eglProperties.setValue(EGL_ALPHA_SIZE, alphaSize);
+    eglProperties.setValue(EGL_DEPTH_SIZE, depthSize);
+    eglProperties.setValue(EGL_STENCIL_SIZE, stencilSize);
+    eglProperties.setValue(EGL_SAMPLES, sampleCount);
+    eglProperties.setValue(EGL_SAMPLE_BUFFERS, sampleCount ? 1 : 0);
 }
 
 
diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp
index 81eb35c..a7c92cf 100644
--- a/src/opengl/qgl_x11egl.cpp
+++ b/src/opengl/qgl_x11egl.cpp
@@ -198,10 +198,6 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
         configProps.setRenderableType(QEgl::OpenGL);
         qt_eglproperties_set_glformat(configProps, d->glFormat);
 
-        // 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);
-
         if (!d->eglContext->chooseConfig(configProps, QEgl::BestPixelFormat)) {
             delete d->eglContext;
             d->eglContext = 0;
-- 
cgit v0.12


From 66e22b5b65b09cf4824dbfbc91e8dea04e8e4214 Mon Sep 17 00:00:00 2001
From: Thierry Bastian <thierry.bastian@nokia.com>
Date: Wed, 10 Mar 2010 09:41:11 +0100
Subject: MAke the SIMD fiunctions be used even when the QT_NO_DEBUG macro is
 used

Reviewed-by: Benjamin Poulain
---
 src/gui/painting/qdrawhelper.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index 5f70cb7..581b538 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -7820,7 +7820,6 @@ void qInitDrawhelperAsm()
     CompositionFunction *functionForModeAsm = 0;
     CompositionFunctionSolid *functionForModeSolidAsm = 0;
 
-#ifdef QT_NO_DEBUG
     const uint features = qDetectCPUFeatures();
     if (false) {
 #ifdef QT_HAVE_SSE2
@@ -7944,8 +7943,6 @@ void qInitDrawhelperAsm()
     }
 #endif // IWMMXT
 
-#endif // QT_NO_DEBUG
-
 #if defined(Q_CC_RVCT) && defined(QT_HAVE_ARMV6)
         functionForModeAsm = qt_functionForMode_ARMv6;
         functionForModeSolidAsm = qt_functionForModeSolid_ARMv6;
-- 
cgit v0.12