From 43b3307bebb9600954e48b0a3b341d5d9b2b26de Mon Sep 17 00:00:00 2001
From: Tom Cooksey <thomas.cooksey@nokia.com>
Date: Tue, 20 Oct 2009 08:57:39 +0200
Subject: Fix build on desktop X11

Hash-Define out X11GL pixmap data until the GLX implementation is ready.
---
 src/opengl/qgraphicssystem_gl.cpp | 2 +-
 src/opengl/qpixmapdata_x11gl_p.h  | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/opengl/qgraphicssystem_gl.cpp b/src/opengl/qgraphicssystem_gl.cpp
index 60d58a7..0ee1e82 100644
--- a/src/opengl/qgraphicssystem_gl.cpp
+++ b/src/opengl/qgraphicssystem_gl.cpp
@@ -57,7 +57,7 @@ extern QGLWidget *qt_gl_getShareWidget();
 
 QPixmapData *QGLGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const
 {
-#ifdef Q_WS_X11
+#if defined(Q_WS_X11) && defined(QT_OPENGL_ES)
     if (type == QPixmapData::PixmapType && QX11GLPixmapData::hasX11GLPixmaps())
         return new QX11GLPixmapData();
 #endif
diff --git a/src/opengl/qpixmapdata_x11gl_p.h b/src/opengl/qpixmapdata_x11gl_p.h
index 3e09ba9..bba9bb3 100644
--- a/src/opengl/qpixmapdata_x11gl_p.h
+++ b/src/opengl/qpixmapdata_x11gl_p.h
@@ -74,11 +74,9 @@ public:
     QGLContext* context() const;
     QSize size() const;
 
-
     static bool hasX11GLPixmaps();
     static QGLFormat glFormat();
 private:
-    static void createPixmapSharedContext(EGLConfig config);
     mutable QGLContext* ctx;
 };
 
-- 
cgit v0.12


From 23b058cdf3d98439ec784a3d430d54e5aed75c7b Mon Sep 17 00:00:00 2001
From: Trond Kjernaasen <trond@trolltech.com>
Date: Tue, 20 Oct 2009 10:37:09 +0200
Subject: Fixed a stencil clearing bug in the GL 1 engine.

If the system clip changed the stencil buffer wasn't necessarily updated
correctly. Use a region to keep track of the dirty areas in the stencil
buffer, like we do in the GL 2 engine.

Reviewed-by: Samuel
---
 src/opengl/qpaintengine_opengl.cpp | 40 ++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp
index 80628a2..aa6b6c9 100644
--- a/src/opengl/qpaintengine_opengl.cpp
+++ b/src/opengl/qpaintengine_opengl.cpp
@@ -746,7 +746,6 @@ public:
     uint has_brush : 1;
     uint has_fast_pen : 1;
     uint use_stencil_method : 1;
-    uint dirty_stencil : 1;
     uint dirty_drawable_texture : 1;
     uint has_stencil_face_ext : 1;
     uint use_fragment_programs : 1;
@@ -757,6 +756,8 @@ public:
     uint use_system_clip : 1;
     uint use_emulation : 1;
 
+    QRegion dirty_stencil;
+
     void updateUseEmulation();
 
     QTransform matrix;
@@ -1259,7 +1260,9 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev)
     d->matrix = QTransform();
     d->has_antialiasing = false;
     d->high_quality_antialiasing = false;
-    d->dirty_stencil = true;
+
+    QSize sz(d->device->size());
+    d->dirty_stencil = QRect(0, 0, sz.width(), sz.height());
 
     d->use_emulation = false;
 
@@ -1347,7 +1350,6 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev)
 
     d->offscreen.begin();
 
-    QSize sz(d->device->size());
     glViewport(0, 0, sz.width(), sz.height()); // XXX (Embedded): We need a solution for GLWidgets that draw in a part or a bigger surface...
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
@@ -1949,34 +1951,34 @@ void QOpenGLPaintEnginePrivate::fillVertexArray(Qt::FillRule fillRule)
 {
     Q_Q(QOpenGLPaintEngine);
 
-    if (dirty_stencil) {
-        disableClipping();
+    QRect rect = dirty_stencil.boundingRect();
 
-        if (use_system_clip) {
-            glEnable(GL_SCISSOR_TEST);
+    if (use_system_clip)
+        rect = q->systemClip().intersected(dirty_stencil).boundingRect();
 
-            QRect rect = q->systemClip().boundingRect();
+    glStencilMask(~0);
 
-            const int left = rect.left();
-            const int width = rect.width();
-            const int bottom = device->size().height() - (rect.bottom() + 1);
-            const int height = rect.height();
+    if (!rect.isEmpty()) {
+        disableClipping();
 
-            glScissor(left, bottom, width, height);
-        }
+        glEnable(GL_SCISSOR_TEST);
+
+        const int left = rect.left();
+        const int width = rect.width();
+        const int bottom = device->size().height() - (rect.bottom() + 1);
+        const int height = rect.height();
+
+        glScissor(left, bottom, width, height);
 
         glClearStencil(0);
         glClear(GL_STENCIL_BUFFER_BIT);
-        dirty_stencil = false;
+        dirty_stencil -= rect;
 
-        if (use_system_clip)
-            glDisable(GL_SCISSOR_TEST);
+        glDisable(GL_SCISSOR_TEST);
 
         enableClipping();
     }
 
-    glStencilMask(~0);
-
     // Enable stencil.
     glEnable(GL_STENCIL_TEST);
 
-- 
cgit v0.12


From 6e1e26741e682c869c45e4cf8dfe4c79e37b9716 Mon Sep 17 00:00:00 2001
From: Kim Motoyoshi Kalland <kim.kalland@nokia.com>
Date: Tue, 20 Oct 2009 11:52:42 +0200
Subject: Fixed the SVG paint engine to preserve whitespace when drawing text.

Added xml:space="preserve" to the output text tag. This attribute tells
the SVG user agent not to strip away excess whitespace in the text
element.

Reviewed-by: Trond
---
 src/svg/qsvggenerator.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp
index da3123f..2f80a92 100644
--- a/src/svg/qsvggenerator.cpp
+++ b/src/svg/qsvggenerator.cpp
@@ -1063,6 +1063,7 @@ void QSvgPaintEngine::drawTextItem(const QPointF &pt, const QTextItem &textItem)
                   "fill=\"" << d->attributes.stroke << "\" "
                   "fill-opacity=\"" << d->attributes.strokeOpacity << "\" "
                   "stroke=\"none\" "
+                  "xml:space=\"preserve\" "
                   "x=\"" << pt.x() << "\" y=\"" << pt.y() << "\" ";
     qfontToSvg(textItem.font());
     *d->stream << " >"
-- 
cgit v0.12


From f0a7e831394683190faf8a51bf724462f98568e9 Mon Sep 17 00:00:00 2001
From: Tom Cooksey <thomas.cooksey@nokia.com>
Date: Tue, 20 Oct 2009 14:37:29 +0200
Subject: Add a new window surface which utilises QX11GLPixmapData

The new surface uses XCopyArea to post updates to the window and thus,
supports partial updates.
---
 src/opengl/opengl.pro               |   7 +-
 src/opengl/qgraphicssystem_gl.cpp   |   8 +-
 src/opengl/qwindowsurface_gl.cpp    |   1 +
 src/opengl/qwindowsurface_x11gl.cpp | 146 ++++++++++++++++++++++++++++++++++++
 src/opengl/qwindowsurface_x11gl_p.h |  81 ++++++++++++++++++++
 5 files changed, 239 insertions(+), 4 deletions(-)
 create mode 100644 src/opengl/qwindowsurface_x11gl.cpp
 create mode 100644 src/opengl/qwindowsurface_x11gl_p.h

diff --git a/src/opengl/opengl.pro b/src/opengl/opengl.pro
index 961c781..a212675 100644
--- a/src/opengl/opengl.pro
+++ b/src/opengl/opengl.pro
@@ -83,11 +83,12 @@ x11 {
         SOURCES +=  qgl_x11egl.cpp \
                     qglpixelbuffer_egl.cpp \
                     qgl_egl.cpp \
-                    qpixmapdata_x11gl_egl.cpp
+                    qpixmapdata_x11gl_egl.cpp \
+                    qwindowsurface_x11gl.cpp
 
         HEADERS +=  qgl_egl_p.h \
-                    qpixmapdata_x11gl_p.h
-
+                    qpixmapdata_x11gl_p.h \
+                    qwindowsurface_x11gl_p.h
 
     } else {
         SOURCES +=  qgl_x11.cpp \
diff --git a/src/opengl/qgraphicssystem_gl.cpp b/src/opengl/qgraphicssystem_gl.cpp
index 0ee1e82..c0d9233 100644
--- a/src/opengl/qgraphicssystem_gl.cpp
+++ b/src/opengl/qgraphicssystem_gl.cpp
@@ -47,8 +47,9 @@
 #include "private/qgl_p.h"
 #include <private/qwindowsurface_raster_p.h>
 
-#ifdef Q_WS_X11
+#if defined(Q_WS_X11) && defined(QT_OPENGL_ES)
 #include "private/qpixmapdata_x11gl_p.h"
+#include "private/qwindowsurface_x11gl_p.h"
 #endif
 
 QT_BEGIN_NAMESPACE
@@ -75,6 +76,11 @@ QWindowSurface *QGLGraphicsSystem::createWindowSurface(QWidget *widget) const
         return new QRasterWindowSurface(widget);
 #endif
 
+#if defined(Q_WS_X11) && defined(QT_OPENGL_ES)
+    if (QX11GLPixmapData::hasX11GLPixmaps())
+        return new QX11GLWindowSurface(widget);
+#endif
+
     return new QGLWindowSurface(widget);
 }
 
diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp
index 2816eca..4547416 100644
--- a/src/opengl/qwindowsurface_gl.cpp
+++ b/src/opengl/qwindowsurface_gl.cpp
@@ -364,6 +364,7 @@ void QGLWindowSurface::hijackWindow(QWidget *widget)
     if (ctxpriv->eglSurface == EGL_NO_SURFACE) {
         qWarning() << "hijackWindow() could not create EGL surface";
     }
+    qDebug("QGLWindowSurface - using EGLConfig %d", ctxpriv->eglContext->config());
 #endif
 
     widgetPrivate->extraData()->glContext = ctx;
diff --git a/src/opengl/qwindowsurface_x11gl.cpp b/src/opengl/qwindowsurface_x11gl.cpp
new file mode 100644
index 0000000..2e05ab3
--- /dev/null
+++ b/src/opengl/qwindowsurface_x11gl.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QTime>
+#include <QDebug>
+
+#include <private/qt_x11_p.h>
+#include <private/qimagepixmapcleanuphooks_p.h>
+
+#include "qwindowsurface_x11gl_p.h"
+#include "qpixmapdata_x11gl_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QX11GLWindowSurface::QX11GLWindowSurface(QWidget* window)
+    : QWindowSurface(window), m_GC(0), m_window(window)
+{
+    QImagePixmapCleanupHooks::instance();
+}
+
+QX11GLWindowSurface::~QX11GLWindowSurface()
+{
+
+    if (m_GC)
+        XFree(m_GC);
+}
+
+QPaintDevice *QX11GLWindowSurface::paintDevice()
+{
+    return &m_backBuffer;
+}
+
+extern void *qt_getClipRects(const QRegion &r, int &num); // in qpaintengine_x11.cpp
+
+void QX11GLWindowSurface::flush(QWidget *widget, const QRegion &widgetRegion, const QPoint &offset)
+{
+//    qDebug("QX11GLWindowSurface::flush()");
+    QTime startTime = QTime::currentTime();
+    if (m_backBuffer.isNull()) {
+        qDebug("QHarmattanWindowSurface::flush() - backBuffer is null, not flushing anything");
+        return;
+    }
+
+    QPoint widgetOffset = qt_qwidget_data(widget)->wrect.topLeft();
+    QRegion windowRegion(widgetRegion);
+    QRect boundingRect = widgetRegion.boundingRect();
+    if (!widgetOffset.isNull())
+        windowRegion.translate(-widgetOffset);
+    QRect windowBoundingRect = windowRegion.boundingRect();
+
+    int rectCount;
+    XRectangle *rects = (XRectangle *)qt_getClipRects(windowRegion, rectCount);
+    if (rectCount <= 0)
+        return;
+//         qDebug() << "XSetClipRectangles";
+//         for  (int i = 0; i < num; ++i)
+//             qDebug() << ' ' << i << rects[i].x << rects[i].x << rects[i].y << rects[i].width << rects[i].height;
+
+    if (m_GC == 0) {
+        m_GC = XCreateGC(X11->display, m_window->handle(), 0, 0);
+        XSetGraphicsExposures(X11->display, m_GC, False);
+    }
+
+    XSetClipRectangles(X11->display, m_GC, 0, 0, rects, rectCount, YXBanded);
+    XCopyArea(X11->display, m_backBuffer.handle(), m_window->handle(), m_GC,
+              boundingRect.x() + offset.x(), boundingRect.y() + offset.y(),
+              boundingRect.width(), boundingRect.height(),
+              windowBoundingRect.x(), windowBoundingRect.y());
+}
+
+void QX11GLWindowSurface::setGeometry(const QRect &rect)
+{
+    if (rect.width() > m_backBuffer.size().width() || rect.height() > m_backBuffer.size().height()) {
+        QSize newSize = rect.size();
+//        QSize newSize(1024,512);
+        qDebug() << "QX11GLWindowSurface::setGeometry() - creating a pixmap of size" << newSize;
+        QX11GLPixmapData *pd = new QX11GLPixmapData;
+        pd->resize(newSize.width(), newSize.height());
+        m_backBuffer = QPixmap(pd);
+    }
+
+//    if (gc)
+//        XFreeGC(X11->display, gc);
+//    gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0);
+//    XSetGraphicsExposures(X11->display, gc, False);
+    QWindowSurface::setGeometry(rect);
+}
+
+bool QX11GLWindowSurface::scroll(const QRegion &area, int dx, int dy)
+{
+    return false;
+}
+
+/*
+void QX11GLWindowSurface::beginPaint(const QRegion &region)
+{
+}
+
+void QX11GLWindowSurface::endPaint(const QRegion &region)
+{
+}
+
+QImage *QX11GLWindowSurface::buffer(const QWidget *widget)
+{
+}
+*/
+
+QT_END_NAMESPACE
diff --git a/src/opengl/qwindowsurface_x11gl_p.h b/src/opengl/qwindowsurface_x11gl_p.h
new file mode 100644
index 0000000..5ba4dc5
--- /dev/null
+++ b/src/opengl/qwindowsurface_x11gl_p.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWINDOWSURFACE_X11GL_P_H
+#define QWINDOWSURFACE_X11GL_P_H
+
+//
+//  W A R N I N G
+//  -------------
+//
+// This file is not part of the Qt API.  It exists purely as an
+// implementation detail.  This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qwindowsurface_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QX11GLWindowSurface : public QWindowSurface
+{
+public:
+    QX11GLWindowSurface(QWidget* window);
+    virtual ~QX11GLWindowSurface();
+
+    // Inherreted from QWindowSurface
+    QPaintDevice *paintDevice();
+    void flush(QWidget *widget, const QRegion &region, const QPoint &offset);
+    void setGeometry(const QRect &rect);
+    bool scroll(const QRegion &area, int dx, int dy);
+
+private:
+    GC      m_GC;
+    QPixmap m_backBuffer;
+    QWidget *m_window;
+};
+
+
+QT_END_NAMESPACE
+
+#endif // QWINDOWSURFACE_X11GL_P_H
-- 
cgit v0.12


From bdb67474ece69a987379411f593d0b37c1400746 Mon Sep 17 00:00:00 2001
From: Tom Cooksey <thomas.cooksey@nokia.com>
Date: Tue, 20 Oct 2009 14:54:22 +0200
Subject: Make sure QGLTextureCache exists when creating surfaces for pixmaps

QGLTextureCache installs pixmap cleanup hooks which are used to clean up
the EGL surfaces.

Reviewed-By: Trustme
---
 src/opengl/qgl_x11egl.cpp           | 8 ++++++++
 src/opengl/qwindowsurface_x11gl.cpp | 2 --
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp
index fb08741..3894ed1 100644
--- a/src/opengl/qgl_x11egl.cpp
+++ b/src/opengl/qgl_x11egl.cpp
@@ -521,6 +521,14 @@ bool Q_OPENGL_EXPORT qt_createEGLSurfaceForPixmap(QPixmapData* pmd, bool readOnl
         return false;
     }
 
+    static bool doneOnce = false;
+    if (!doneOnce) {
+        // Make sure QGLTextureCache is instanciated so it can install cleanup hooks
+        // which cleanup the EGL surface.
+        QGLTextureCache::instance();
+        doneOnce = true;
+    }
+
     Q_ASSERT(sizeof(Qt::HANDLE) >= sizeof(EGLSurface)); // Just to make totally sure!
     pixmapData->gl_surface = (Qt::HANDLE)pixmapSurface;
     pixmapData->is_cached = true; // Make sure the cleanup hook gets called
diff --git a/src/opengl/qwindowsurface_x11gl.cpp b/src/opengl/qwindowsurface_x11gl.cpp
index 2e05ab3..8ef239d 100644
--- a/src/opengl/qwindowsurface_x11gl.cpp
+++ b/src/opengl/qwindowsurface_x11gl.cpp
@@ -53,12 +53,10 @@ QT_BEGIN_NAMESPACE
 QX11GLWindowSurface::QX11GLWindowSurface(QWidget* window)
     : QWindowSurface(window), m_GC(0), m_window(window)
 {
-    QImagePixmapCleanupHooks::instance();
 }
 
 QX11GLWindowSurface::~QX11GLWindowSurface()
 {
-
     if (m_GC)
         XFree(m_GC);
 }
-- 
cgit v0.12


From 84cfe9af5e333872ac67368a6b14c377ceeda8ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= <trond@trolltech.com>
Date: Tue, 20 Oct 2009 17:51:15 +0200
Subject: Fixed an assert when running the composition demo on Mac.

We can't create a QGLWidget in the QGLEngineSelector, since it may
be called before a QApplication object has been constructed.

Reviewed-by: Kim
---
 src/opengl/qgl.cpp | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 97e3dad..6720ae7 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -151,22 +151,6 @@ class QGLEngineSelector
 public:
     QGLEngineSelector() : engineType(QPaintEngine::MaxUser)
     {
-#ifdef Q_WS_MAC
-        // The ATI X1600 driver for Mac OS X does not support return
-        // values from functions in GLSL. Since working around this in
-        // the GL2 engine would require a big, ugly rewrite, we're
-        // falling back to the GL 1 engine..
-        QGLWidget *tmp = 0;
-        if (!QGLContext::currentContext()) {
-            tmp = new QGLWidget();
-            tmp->makeCurrent();
-        }
-        if (strstr((char *) glGetString(GL_RENDERER), "X1600"))
-            setPreferredPaintEngine(QPaintEngine::OpenGL);
-        if (tmp)
-            delete tmp;
-#endif
-
     }
 
     void setPreferredPaintEngine(QPaintEngine::Type type) {
@@ -175,6 +159,25 @@ public:
     }
 
     QPaintEngine::Type preferredPaintEngine() {
+#ifdef Q_WS_MAC
+        // The ATI X1600 driver for Mac OS X does not support return
+        // values from functions in GLSL. Since working around this in
+        // the GL2 engine would require a big, ugly rewrite, we're
+        // falling back to the GL 1 engine..
+        static bool mac_x1600_check_done = false;
+        if (!mac_x1600_check_done) {
+            QGLWidget *tmp = 0;
+            if (!QGLContext::currentContext()) {
+                tmp = new QGLWidget();
+                tmp->makeCurrent();
+            }
+            if (strstr((char *) glGetString(GL_RENDERER), "X1600"))
+                engineType = QPaintEngine::OpenGL;
+            if (tmp)
+                delete tmp;
+            mac_x1600_check_done = true;
+        }
+#endif
         if (engineType == QPaintEngine::MaxUser) {
             // No user-set engine - use the defaults
 #if defined(QT_OPENGL_ES_2)
-- 
cgit v0.12


From 3be273fc751624fab078878904ad3cb483cd141f Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Date: Wed, 21 Oct 2009 13:31:07 +0200
Subject: Properly detect font smoothing setting on Mac OS X in raster engine
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We would assume font smoothing on the mac was always turned on, giving
poor text rendering in the cases where it was not. This implementation
mirrors querying the cleartype setting on Windows, checking the setting
on application initialization and rendering into an 8 bit cache if it
is turned off.

Task-number: QTBUG-4881
Reviewed-by: Morten Johan Sørvig
---
 src/gui/kernel/qapplication_mac.mm       | 11 +++++++++++
 src/gui/painting/qpaintengine_raster.cpp |  6 +++++-
 src/gui/painting/qtextureglyphcache.cpp  |  4 ++--
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm
index f9c8aa3..771cddc 100644
--- a/src/gui/kernel/qapplication_mac.mm
+++ b/src/gui/kernel/qapplication_mac.mm
@@ -203,6 +203,8 @@ static EventHandlerRef tablet_proximity_handler = 0;
 static EventHandlerUPP tablet_proximity_UPP = 0;
 bool QApplicationPrivate::native_modal_dialog_active;
 
+Q_GUI_EXPORT bool qt_applefontsmoothing_enabled;
+
 /*****************************************************************************
   External functions
  *****************************************************************************/
@@ -222,6 +224,12 @@ extern bool qt_sendSpontaneousEvent(QObject *obj, QEvent *event); // qapplicatio
 void onApplicationWindowChangedActivation( QWidget*widget, bool activated );
 void onApplicationChangedActivation( bool activated );
 
+static void qt_mac_read_fontsmoothing_settings()
+{
+    NSInteger appleFontSmoothing = [[NSUserDefaults standardUserDefaults] integerForKey:@"AppleFontSmoothing"];
+    qt_applefontsmoothing_enabled = (appleFontSmoothing > 0);
+}
+
 Q_GUI_EXPORT bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) {
     OSStatus err;
     AEDesc scriptTextDesc;
@@ -1203,6 +1211,9 @@ void qt_init(QApplicationPrivate *priv, int)
     }
     if (QApplication::desktopSettingsAware())
         QApplicationPrivate::qt_mac_apply_settings();
+
+    qt_mac_read_fontsmoothing_settings();
+
     // Cocoa application delegate
 #ifdef QT_MAC_USE_COCOA
     NSApplication *cocoaApp = [NSApplication sharedApplication];
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index fab2d8d..fd0e810 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -132,6 +132,10 @@ static const qreal aliasedCoordinateDelta = 0.5 - 0.015625;
 extern bool qt_cleartype_enabled;
 #endif
 
+#ifdef Q_WS_MAC
+extern bool qt_applefontsmoothing_enabled;
+#endif
+
 
 /********************************************************************************
  * Span functions
@@ -508,7 +512,7 @@ bool QRasterPaintEngine::begin(QPaintDevice *device)
 #if defined(Q_WS_WIN)
     else if (qt_cleartype_enabled)
 #elif defined (Q_WS_MAC)
-    else if (true)
+    else if (qt_applefontsmoothing_enabled)
 #else
     else if (false)
 #endif
diff --git a/src/gui/painting/qtextureglyphcache.cpp b/src/gui/painting/qtextureglyphcache.cpp
index 25b6aba..a192e87 100644
--- a/src/gui/painting/qtextureglyphcache.cpp
+++ b/src/gui/painting/qtextureglyphcache.cpp
@@ -229,8 +229,8 @@ void QImageTextureGlyphCache::createTextureData(int width, int height)
 
 int QImageTextureGlyphCache::glyphMargin() const
 {
-#ifdef Q_WS_MAC
-    return 2;
+#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
+    return 0;
 #else
     return m_type == QFontEngineGlyphCache::Raster_RGBMask ? 2 : 0;
 #endif
-- 
cgit v0.12


From cdb98c137db4d051e4b41c9fa4626c4c369cc0b1 Mon Sep 17 00:00:00 2001
From: Kim Motoyoshi Kalland <kim.kalland@nokia.com>
Date: Wed, 21 Oct 2009 13:24:06 +0200
Subject: Improved QFontInfo::pointSize() slightly on X11.

In non-GUI applications on X11, QFont and QFontInfo return different
point size because for QFontInfo, the point size is converted to pixel
size and back, but with different dpis. This commit improves the
situation for the case where font config is used, but the bug still
needs to be fixed properly by using the same dpi for all point<->pixel
size conversions.

Reviewed-by: Trond
---
 src/gui/text/qfontdatabase_x11.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp
index 382c4fe..27ff003 100644
--- a/src/gui/text/qfontdatabase_x11.cpp
+++ b/src/gui/text/qfontdatabase_x11.cpp
@@ -752,7 +752,7 @@ QFontDef qt_FcPatternToQFontDef(FcPattern *pattern, const QFontDef &request)
         if (X11->display)
             dpi = QX11Info::appDpiY();
         else
-            dpi = 96; // ####
+            dpi = qt_defaultDpiY();
     }
 
     double size;
-- 
cgit v0.12