diff options
Diffstat (limited to 'src/gui/painting')
42 files changed, 1215 insertions, 436 deletions
diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri index 8c377d8..37de177 100644 --- a/src/gui/painting/painting.pri +++ b/src/gui/painting/painting.pri @@ -122,6 +122,7 @@ embedded { } else: if(!embedded_lite) { HEADERS += \ painting/qgraphicssystem_raster_p.h \ + painting/qgraphicssystem_runtime_p.h \ painting/qgraphicssystemfactory_p.h \ painting/qgraphicssystemplugin_p.h \ painting/qwindowsurface_raster_p.h \ @@ -129,6 +130,7 @@ embedded { SOURCES += \ painting/qgraphicssystem_raster.cpp \ + painting/qgraphicssystem_runtime.cpp \ painting/qgraphicssystemfactory.cpp \ painting/qgraphicssystemplugin.cpp \ painting/qwindowsurface_raster.cpp \ @@ -249,7 +251,7 @@ contains(QMAKE_MAC_XARCH, no) { IWMMXT_SOURCES += painting/qdrawhelper_iwmmxt.cpp } - win32-g++|!win32:!*-icc* { + win32-g++*|!win32:!*-icc* { mmx { mmx_compiler.commands = $$QMAKE_CXX -c -Winline @@ -418,9 +420,10 @@ neon:*-g++* { } contains(QT_CONFIG, zlib) { - INCLUDEPATH += ../3rdparty/zlib + INCLUDEPATH += ../3rdparty/zlib } else:!contains(QT_CONFIG, no-zlib) { - unix:LIBS_PRIVATE += -lz -# win32:LIBS += libz.lib + symbian:LIBS_PRIVATE += -llibz + else:if(unix|win32-g++*):LIBS_PRIVATE += -lz + else:LIBS += zdll.lib } diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index b158a76..590b9a8 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -935,7 +935,7 @@ void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy) QWidgetPrivate *pd = pw->d_func(); QRect clipR(pd->clipRect()); #ifdef Q_WS_QWS - QWidgetBackingStore *wbs = x->backingStore; + QWidgetBackingStore *wbs = x->backingStore.data(); QWSWindowSurface *surface = static_cast<QWSWindowSurface*>(wbs->windowSurface); clipR = clipR.intersected(surface->clipRegion().translated(-toplevelOffset).boundingRect()); #endif @@ -965,7 +965,7 @@ void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy) invalidateBuffer((newRect & clipR).translated(-data.crect.topLeft())); } else { - QWidgetBackingStore *wbs = x->backingStore; + QWidgetBackingStore *wbs = x->backingStore.data(); QRegion childExpose(newRect & clipR); if (sourceRect.isValid() && wbs->bltRect(sourceRect, dx, dy, pw)) @@ -1008,7 +1008,7 @@ void QWidgetPrivate::scrollRect(const QRect &rect, int dx, int dy) if (x->inTopLevelResize) return; - QWidgetBackingStore *wbs = x->backingStore; + QWidgetBackingStore *wbs = x->backingStore.data(); if (!wbs) return; diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp index 7ff2a37..2a9b31a 100644 --- a/src/gui/painting/qbezier.cpp +++ b/src/gui/painting/qbezier.cpp @@ -93,7 +93,7 @@ QBezier QBezier::fromPoints(const QPointF &p1, const QPointF &p2, /*! \internal */ -QPolygonF QBezier::toPolygon() const +QPolygonF QBezier::toPolygon(qreal bezier_flattening_threshold) const { // flattening is done by splitting the bezier until we can replace the segment by a straight // line. We split further until the control points are close enough to the line connecting the @@ -108,7 +108,7 @@ QPolygonF QBezier::toPolygon() const QPolygonF polygon; polygon.append(QPointF(x1, y1)); - addToPolygon(&polygon); + addToPolygon(&polygon, bezier_flattening_threshold); return polygon; } @@ -117,34 +117,6 @@ QBezier QBezier::mapBy(const QTransform &transform) const return QBezier::fromPoints(transform.map(pt1()), transform.map(pt2()), transform.map(pt3()), transform.map(pt4())); } -//0.05 is really low, but required for scaled-up beziers... -static const qreal flatness = 0.05; - -//based on "Fast, precise flattening of cubic Bezier path and offset curves" -// by T. F. Hain, A. L. Ahmad, S. V. R. Racherla and D. D. Langan -static inline void flattenBezierWithoutInflections(QBezier &bez, - QPolygonF *&p) -{ - QBezier left; - - while (1) { - qreal dx = bez.x2 - bez.x1; - qreal dy = bez.y2 - bez.y1; - - qreal normalized = qSqrt(dx * dx + dy * dy); - if (qFuzzyIsNull(normalized)) - break; - - qreal d = qAbs(dx * (bez.y3 - bez.y2) - dy * (bez.x3 - bez.x2)); - - qreal t = qSqrt(4. / 3. * normalized * flatness / d); - if (t > 1 || qFuzzyIsNull(t - (qreal)1.)) - break; - bez.parameterSplitLeft(t, &left); - p->append(bez.pt1()); - } -} - QBezier QBezier::getSubRange(qreal t0, qreal t1) const { QBezier result; @@ -223,7 +195,7 @@ static inline bool findInflections(qreal a, qreal b, qreal c, } -void QBezier::addToPolygon(QPolygonF *polygon) const +void QBezier::addToPolygon(QPolygonF *polygon, qreal bezier_flattening_threshold) const { QBezier beziers[32]; beziers[0] = *this; @@ -243,7 +215,7 @@ void QBezier::addToPolygon(QPolygonF *polygon) const qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); l = 1.; } - if (d < flatness*l || b == beziers + 31) { + if (d < bezier_flattening_threshold*l || b == beziers + 31) { // good enough, we pop it off and add the endpoint polygon->append(QPointF(b->x4, b->y4)); --b; @@ -255,55 +227,6 @@ void QBezier::addToPolygon(QPolygonF *polygon) const } } -void QBezier::addToPolygonMixed(QPolygonF *polygon) const -{ - qreal ax = -x1 + 3*x2 - 3*x3 + x4; - qreal ay = -y1 + 3*y2 - 3*y3 + y4; - qreal bx = 3*x1 - 6*x2 + 3*x3; - qreal by = 3*y1 - 6*y2 + 3*y3; - qreal cx = -3*x1 + 3*x2; - qreal cy = -3*y1 + 2*y2; - qreal a = 6 * (ay * bx - ax * by); - qreal b = 6 * (ay * cx - ax * cy); - qreal c = 2 * (by * cx - bx * cy); - - if ((qFuzzyIsNull(a) && qFuzzyIsNull(b)) || - (b * b - 4 * a *c) < 0) { - QBezier bez(*this); - flattenBezierWithoutInflections(bez, polygon); - polygon->append(QPointF(x4, y4)); - } else { - QBezier beziers[32]; - beziers[0] = *this; - QBezier *b = beziers; - - while (b >= beziers) { - // check if we can pop the top bezier curve from the stack - qreal y4y1 = b->y4 - b->y1; - qreal x4x1 = b->x4 - b->x1; - qreal l = qAbs(x4x1) + qAbs(y4y1); - qreal d; - if (l > 1.) { - d = qAbs( (x4x1)*(b->y1 - b->y2) - (y4y1)*(b->x1 - b->x2) ) - + qAbs( (x4x1)*(b->y1 - b->y3) - (y4y1)*(b->x1 - b->x3) ); - } else { - d = qAbs(b->x1 - b->x2) + qAbs(b->y1 - b->y2) + - qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); - l = 1.; - } - if (d < .5*l || b == beziers + 31) { - // good enough, we pop it off and add the endpoint - polygon->append(QPointF(b->x4, b->y4)); - --b; - } else { - // split, second half of the polygon goes lower into the stack - b->split(b+1, b); - ++b; - } - } - } -} - QRectF QBezier::bounds() const { qreal xmin = x1; @@ -824,147 +747,4 @@ QBezier QBezier::bezierOnInterval(qreal t0, qreal t1) const return result; } - -static inline void bindInflectionPoint(const QBezier &bez, const qreal t, - qreal *tMinus , qreal *tPlus) -{ - if (t <= 0) { - *tMinus = *tPlus = -1; - return; - } else if (t >= 1) { - *tMinus = *tPlus = 2; - return; - } - - QBezier left, right; - splitBezierAt(bez, t, &left, &right); - - qreal ax = -right.x1 + 3*right.x2 - 3*right.x3 + right.x4; - qreal ay = -right.y1 + 3*right.y2 - 3*right.y3 + right.y4; - qreal ex = 3 * (right.x2 - right.x3); - qreal ey = 3 * (right.y2 - right.y3); - - qreal s4 = qAbs(6 * (ey * ax - ex * ay) / qSqrt(ex * ex + ey * ey)) + 0.00001f; - qreal tf = qPow(qreal(9 * flatness / s4), qreal(1./3.)); - *tMinus = t - (1 - t) * tf; - *tPlus = t + (1 - t) * tf; -} - -void QBezier::addToPolygonIterative(QPolygonF *p) const -{ - qreal t1, t2, tcusp; - qreal t1min, t1plus, t2min, t2plus; - - qreal ax = -x1 + 3*x2 - 3*x3 + x4; - qreal ay = -y1 + 3*y2 - 3*y3 + y4; - qreal bx = 3*x1 - 6*x2 + 3*x3; - qreal by = 3*y1 - 6*y2 + 3*y3; - qreal cx = -3*x1 + 3*x2; - qreal cy = -3*y1 + 2*y2; - - if (findInflections(6 * (ay * bx - ax * by), - 6 * (ay * cx - ax * cy), - 2 * (by * cx - bx * cy), - &t1, &t2, &tcusp)) { - bindInflectionPoint(*this, t1, &t1min, &t1plus); - bindInflectionPoint(*this, t2, &t2min, &t2plus); - - QBezier tmpBez = *this; - QBezier left, right, bez1, bez2, bez3; - if (t1min > 0) { - if (t1min >= 1) { - flattenBezierWithoutInflections(tmpBez, p); - } else { - splitBezierAt(tmpBez, t1min, &left, &right); - flattenBezierWithoutInflections(left, p); - p->append(tmpBez.pointAt(t1min)); - - if (t2min < t1plus) { - if (tcusp < 1) { - p->append(tmpBez.pointAt(tcusp)); - } - if (t2plus < 1) { - splitBezierAt(tmpBez, t2plus, &left, &right); - flattenBezierWithoutInflections(right, p); - } - } else if (t1plus < 1) { - if (t2min < 1) { - splitBezierAt(tmpBez, t2min, &bez3, &right); - splitBezierAt(bez3, t1plus, &left, &bez2); - - flattenBezierWithoutInflections(bez2, p); - p->append(tmpBez.pointAt(t2min)); - - if (t2plus < 1) { - splitBezierAt(tmpBez, t2plus, &left, &bez2); - flattenBezierWithoutInflections(bez2, p); - } - } else { - splitBezierAt(tmpBez, t1plus, &left, &bez2); - flattenBezierWithoutInflections(bez2, p); - } - } - } - } else if (t1plus > 0) { - p->append(QPointF(x1, y1)); - if (t2min < t1plus) { - if (tcusp < 1) { - p->append(tmpBez.pointAt(tcusp)); - } - if (t2plus < 1) { - splitBezierAt(tmpBez, t2plus, &left, &bez2); - flattenBezierWithoutInflections(bez2, p); - } - } else if (t1plus < 1) { - if (t2min < 1) { - splitBezierAt(tmpBez, t2min, &bez3, &right); - splitBezierAt(bez3, t1plus, &left, &bez2); - - flattenBezierWithoutInflections(bez2, p); - - p->append(tmpBez.pointAt(t2min)); - if (t2plus < 1) { - splitBezierAt(tmpBez, t2plus, &left, &bez2); - flattenBezierWithoutInflections(bez2, p); - } - } else { - splitBezierAt(tmpBez, t1plus, &left, &bez2); - flattenBezierWithoutInflections(bez2, p); - } - } - } else if (t2min > 0) { - if (t2min < 1) { - splitBezierAt(tmpBez, t2min, &bez1, &right); - flattenBezierWithoutInflections(bez1, p); - p->append(tmpBez.pointAt(t2min)); - - if (t2plus < 1) { - splitBezierAt(tmpBez, t2plus, &left, &bez2); - flattenBezierWithoutInflections(bez2, p); - } - } else { - //### in here we should check whether the area of the - // triangle formed between pt1/pt2/pt3 is smaller - // or equal to 0 and then do iterative flattening - // if not we should fallback and do the recursive - // flattening. - flattenBezierWithoutInflections(tmpBez, p); - } - } else if (t2plus > 0) { - p->append(QPointF(x1, y1)); - if (t2plus < 1) { - splitBezierAt(tmpBez, t2plus, &left, &bez2); - flattenBezierWithoutInflections(bez2, p); - } - } else { - flattenBezierWithoutInflections(tmpBez, p); - } - } else { - QBezier bez = *this; - flattenBezierWithoutInflections(bez, p); - } - - p->append(QPointF(x4, y4)); -} - QT_END_NAMESPACE diff --git a/src/gui/painting/qbezier_p.h b/src/gui/painting/qbezier_p.h index 846635f..18ec116 100644 --- a/src/gui/painting/qbezier_p.h +++ b/src/gui/painting/qbezier_p.h @@ -79,10 +79,9 @@ public: inline QPointF derivedAt(qreal t) const; inline QPointF secondDerivedAt(qreal t) const; - QPolygonF toPolygon() const; - void addToPolygon(QPolygonF *p) const; - void addToPolygonIterative(QPolygonF *p) const; - void addToPolygonMixed(QPolygonF *p) const; + QPolygonF toPolygon(qreal bezier_flattening_threshold = 0.5) const; + void addToPolygon(QPolygonF *p, qreal bezier_flattening_threshold = 0.5) const; + QRectF bounds() const; qreal length(qreal error = 0.01) const; void addIfClose(qreal *length, qreal error) const; diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 96d547b..d3061d8 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -48,6 +48,7 @@ #include "qline.h" #include "qdebug.h" #include <QtCore/qcoreapplication.h> +#include "private/qstylehelper_p.h" QT_BEGIN_NAMESPACE @@ -96,9 +97,11 @@ const uchar *qt_patternForBrush(int brushStyle, bool invert) QPixmap qt_pixmapForBrush(int brushStyle, bool invert) { + QPixmap pm; - QString key = QLatin1String("$qt-brush$") + QString::number(brushStyle) - + QString::number((int)invert); + QString key = QLatin1Literal("$qt-brush$") + % HexString<uint>(brushStyle) + % QLatin1Char(invert ? '1' : '0'); if (!QPixmapCache::find(key, pm)) { pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert), QImage::Format_MonoLSB); @@ -329,8 +332,8 @@ struct QBrushDataPointerDeleter \endtable - For more information about painting in general, see \l{The Paint - System} documentation. + For more information about painting in general, see the \l{Paint + System}. \sa Qt::BrushStyle, QPainter, QColor */ @@ -1013,7 +1016,7 @@ QDebug operator<<(QDebug dbg, const QBrush &b) Writes the given \a brush to the given \a stream and returns a reference to the \a stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &s, const QBrush &b) @@ -1081,7 +1084,7 @@ QDataStream &operator<<(QDataStream &s, const QBrush &b) Reads the given \a brush from the given \a stream and returns a reference to the \a stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &s, QBrush &b) diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 08d5572..37d7fa3 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -133,7 +133,7 @@ QT_BEGIN_NAMESPACE QColor is platform and device independent. The QColormap class maps the color to the hardware. - For more information about painting in general, see \l{The Paint + For more information about painting in general, see the \l{Paint System} documentation. \tableofcontents @@ -2523,7 +2523,7 @@ QDebug operator<<(QDebug dbg, const QColor &c) Writes the \a color to the \a stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &stream, const QColor &color) { @@ -2559,7 +2559,7 @@ QDataStream &operator<<(QDataStream &stream, const QColor &color) Reads the \a color from the \a stream. - \sa { Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &stream, QColor &color) { diff --git a/src/gui/painting/qdatabuffer_p.h b/src/gui/painting/qdatabuffer_p.h index bc5f1ef..8f8544f 100644 --- a/src/gui/painting/qdatabuffer_p.h +++ b/src/gui/painting/qdatabuffer_p.h @@ -60,16 +60,20 @@ QT_BEGIN_NAMESPACE template <typename Type> class QDataBuffer { public: - QDataBuffer(int res = 64) + QDataBuffer(int res) { capacity = res; - buffer = (Type*) qMalloc(capacity * sizeof(Type)); + if (res) + buffer = (Type*) qMalloc(capacity * sizeof(Type)); + else + buffer = 0; siz = 0; } ~QDataBuffer() { - qFree(buffer); + if (buffer) + qFree(buffer); } inline void reset() { siz = 0; } @@ -104,6 +108,8 @@ public: inline void reserve(int size) { if (size > capacity) { + if (capacity == 0) + capacity = 1; while (capacity < size) capacity *= 2; buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); @@ -112,7 +118,12 @@ public: inline void shrink(int size) { capacity = size; - buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); + if (size) + buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); + else { + qFree(buffer); + buffer = 0; + } } inline void swap(QDataBuffer<Type> &other) { diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp index a62f06b..11ea6d5 100644 --- a/src/gui/painting/qdrawutil.cpp +++ b/src/gui/painting/qdrawutil.cpp @@ -48,6 +48,7 @@ #include <private/qpaintengineex_p.h> #include <qvarlengtharray.h> #include <qmath.h> +#include <private/qstylehelper_p.h> QT_BEGIN_NAMESPACE @@ -1018,7 +1019,9 @@ void qDrawItem(QPainter *p, Qt::GUIStyle gs, ; #ifndef QT_NO_IMAGE_HEURISTIC_MASK } else { // color pixmap, no mask - QString k = QString::fromLatin1("$qt-drawitem-%1").arg(pm.cacheKey()); + QString k = QLatin1Literal("$qt-drawitem") + % HexString<qint64>(pm.cacheKey()); + if (!QPixmapCache::find(k, pm)) { pm = pm.createHeuristicMask(); pm.setMask((QBitmap&)pm); @@ -1137,6 +1140,13 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin xTarget.resize(columns + 1); yTarget.resize(rows + 1); + bool oldAA = painter->testRenderHint(QPainter::Antialiasing); + if (painter->paintEngine()->type() != QPaintEngine::OpenGL + && painter->paintEngine()->type() != QPaintEngine::OpenGL2 + && oldAA && painter->combinedTransform().type() != QTransform::TxNone) { + painter->setRenderHint(QPainter::Antialiasing, false); + } + xTarget[0] = targetRect.left(); xTarget[1] = targetCenterLeft; xTarget[columns - 1] = targetCenterRight; @@ -1342,6 +1352,9 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin painter->drawPixmapFragments(opaqueData.data(), opaqueData.size(), pixmap, QPainter::OpaqueHint); if (translucentData.size()) painter->drawPixmapFragments(translucentData.data(), translucentData.size(), pixmap); + + if (oldAA) + painter->setRenderHint(QPainter::Antialiasing, true); } QT_END_NAMESPACE diff --git a/src/gui/painting/qgraphicssystem_runtime.cpp b/src/gui/painting/qgraphicssystem_runtime.cpp new file mode 100644 index 0000000..32a8578 --- /dev/null +++ b/src/gui/painting/qgraphicssystem_runtime.cpp @@ -0,0 +1,487 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 <private/qgraphicssystem_runtime_p.h> +#include <private/qgraphicssystem_raster_p.h> +#include <private/qgraphicssystemfactory_p.h> +#include <private/qapplication_p.h> +#include <private/qwidget_p.h> +#include <QtCore/QDebug> +#include <QtCore/QTimer> +#include <QtGui/QBitmap> + +QT_BEGIN_NAMESPACE + +static int qt_pixmap_serial = 0; + +#define READBACK(f) \ + m_graphicsSystem->decreaseMemoryUsage(memoryUsage()); \ + f \ + readBackInfo(); \ + m_graphicsSystem->increaseMemoryUsage(memoryUsage()); \ + + +class QDeferredGraphicsSystemChange : public QObject +{ + Q_OBJECT + +public: + QDeferredGraphicsSystemChange(QRuntimeGraphicsSystem *gs, const QString& graphicsSystemName) + : m_graphicsSystem(gs), m_graphicsSystemName(graphicsSystemName) + { + } + + void launch() + { + QTimer::singleShot(0, this, SLOT(doChange())); + } + +private slots: + + void doChange() + { + m_graphicsSystem->setGraphicsSystem(m_graphicsSystemName); + deleteLater(); + } + +private: + + QRuntimeGraphicsSystem *m_graphicsSystem; + QString m_graphicsSystemName; +}; + +QRuntimePixmapData::QRuntimePixmapData(const QRuntimeGraphicsSystem *gs, PixelType type) + : QPixmapData(type, RuntimeClass), m_graphicsSystem(gs) +{ + setSerialNumber(++qt_pixmap_serial); +} + +QRuntimePixmapData::~QRuntimePixmapData() +{ + m_graphicsSystem->removePixmapData(this); + delete m_data; +} + +void QRuntimePixmapData::readBackInfo() +{ + w = m_data->width(); + h = m_data->height(); + d = m_data->depth(); + is_null = m_data->isNull(); +} + + +QPixmapData *QRuntimePixmapData::createCompatiblePixmapData() const +{ + QRuntimePixmapData *rtData = new QRuntimePixmapData(m_graphicsSystem, pixelType()); + rtData->m_data = m_data->createCompatiblePixmapData(); + return rtData; +} + + +void QRuntimePixmapData::resize(int width, int height) +{ + READBACK( + m_data->resize(width, height); + ) +} + + +void QRuntimePixmapData::fromImage(const QImage &image, + Qt::ImageConversionFlags flags) +{ + READBACK( + m_data->fromImage(image, flags); + ) +} + + +bool QRuntimePixmapData::fromFile(const QString &filename, const char *format, + Qt::ImageConversionFlags flags) +{ + bool success(false); + READBACK( + success = m_data->fromFile(filename, format, flags); + ) + return success; +} + +bool QRuntimePixmapData::fromData(const uchar *buffer, uint len, const char *format, + Qt::ImageConversionFlags flags) +{ + bool success(false); + READBACK( + success = m_data->fromData(buffer, len, format, flags); + ) + return success; +} + + +void QRuntimePixmapData::copy(const QPixmapData *data, const QRect &rect) +{ + if (data->runtimeData()) { + READBACK( + m_data->copy(data->runtimeData(), rect); + ) + } else { + READBACK( + m_data->copy(data, rect); + ) + } +} + +bool QRuntimePixmapData::scroll(int dx, int dy, const QRect &rect) +{ + return m_data->scroll(dx, dy, rect); +} + + +int QRuntimePixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const +{ + return m_data->metric(metric); +} + +void QRuntimePixmapData::fill(const QColor &color) +{ + return m_data->fill(color); +} + +QBitmap QRuntimePixmapData::mask() const +{ + return m_data->mask(); +} + +void QRuntimePixmapData::setMask(const QBitmap &mask) +{ + READBACK( + m_data->setMask(mask); + ) +} + +bool QRuntimePixmapData::hasAlphaChannel() const +{ + return m_data->hasAlphaChannel(); +} + +QPixmap QRuntimePixmapData::transformed(const QTransform &matrix, + Qt::TransformationMode mode) const +{ + return m_data->transformed(matrix, mode); +} + +void QRuntimePixmapData::setAlphaChannel(const QPixmap &alphaChannel) +{ + READBACK( + m_data->setAlphaChannel(alphaChannel); + ) +} + +QPixmap QRuntimePixmapData::alphaChannel() const +{ + return m_data->alphaChannel(); +} + +QImage QRuntimePixmapData::toImage() const +{ + return m_data->toImage(); +} + +QPaintEngine* QRuntimePixmapData::paintEngine() const +{ + return m_data->paintEngine(); +} + +QImage* QRuntimePixmapData::buffer() +{ + return m_data->buffer(); +} + +#if defined(Q_OS_SYMBIAN) +void* QRuntimePixmapData::toNativeType(NativeType type) +{ + return m_data->toNativeType(type); +} + +void QRuntimePixmapData::fromNativeType(void *pixmap, NativeType type) +{ + m_data->fromNativeType(pixmap, type); + readBackInfo(); +} +#endif + +QPixmapData* QRuntimePixmapData::runtimeData() const +{ + return m_data; +} + +uint QRuntimePixmapData::memoryUsage() const +{ + if(is_null || d == 0) + return 0; + return w * h * (d / 8); +} + + +QRuntimeWindowSurface::QRuntimeWindowSurface(const QRuntimeGraphicsSystem *gs, QWidget *window) + : QWindowSurface(window), m_windowSurface(0), m_pendingWindowSurface(0), m_graphicsSystem(gs) +{ + +} + +QRuntimeWindowSurface::~QRuntimeWindowSurface() +{ + m_graphicsSystem->removeWindowSurface(this); + delete m_windowSurface; +} + +QPaintDevice *QRuntimeWindowSurface::paintDevice() +{ + return m_windowSurface->paintDevice(); +} + +void QRuntimeWindowSurface::flush(QWidget *widget, const QRegion ®ion, + const QPoint &offset) +{ + m_windowSurface->flush(widget, region, offset); + + int destroyPolicy = m_graphicsSystem->windowSurfaceDestroyPolicy(); + if(m_pendingWindowSurface && + destroyPolicy == QRuntimeGraphicsSystem::DestroyAfterFirstFlush) { +#ifdef QT_DEBUG + qDebug() << "QRuntimeWindowSurface::flush() - destroy pending window surface"; +#endif + delete m_pendingWindowSurface; + m_pendingWindowSurface = 0; + } +} + +void QRuntimeWindowSurface::setGeometry(const QRect &rect) +{ + m_graphicsSystem->decreaseMemoryUsage(memoryUsage()); + m_windowSurface->setGeometry(rect); + m_graphicsSystem->increaseMemoryUsage(memoryUsage()); +} + +bool QRuntimeWindowSurface::scroll(const QRegion &area, int dx, int dy) +{ + return m_windowSurface->scroll(area, dx, dy); +} + +void QRuntimeWindowSurface::beginPaint(const QRegion &rgn) +{ + m_windowSurface->beginPaint(rgn); +} + +void QRuntimeWindowSurface::endPaint(const QRegion &rgn) +{ + m_windowSurface->endPaint(rgn); +} + +QImage* QRuntimeWindowSurface::buffer(const QWidget *widget) +{ + return m_windowSurface->buffer(widget); +} + +QPixmap QRuntimeWindowSurface::grabWidget(const QWidget *widget, const QRect& rectangle) const +{ + return m_windowSurface->grabWidget(widget, rectangle); +} + +QPoint QRuntimeWindowSurface::offset(const QWidget *widget) const +{ + return m_windowSurface->offset(widget); +} + +uint QRuntimeWindowSurface::memoryUsage() const +{ + QPaintDevice *pdev = m_windowSurface->paintDevice(); + if (pdev && pdev->depth() != 0) + return pdev->width() * pdev->height() * (pdev->depth()/8); + + return 0; +} + +QRuntimeGraphicsSystem::QRuntimeGraphicsSystem() + : m_memoryUsage(0), m_windowSurfaceDestroyPolicy(DestroyImmediately), + m_graphicsSystem(0), m_graphicsSystemChangeMemoryLimit(0) +{ + QApplicationPrivate::graphics_system_name = QLatin1String("runtime"); + QApplicationPrivate::runtime_graphics_system = true; + +#ifdef Q_OS_SYMBIAN + m_graphicsSystemName = QLatin1String("openvg"); + m_windowSurfaceDestroyPolicy = DestroyAfterFirstFlush; +#else + m_graphicsSystemName = QLatin1String("raster"); +#endif + + m_graphicsSystem = QGraphicsSystemFactory::create(m_graphicsSystemName); +} + + +QPixmapData *QRuntimeGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const +{ + Q_ASSERT(m_graphicsSystem); + QPixmapData *data = m_graphicsSystem->createPixmapData(type); + + QRuntimePixmapData *rtData = new QRuntimePixmapData(this, type); + rtData->m_data = data; + m_pixmapDatas << rtData; + + return rtData; +} + +QWindowSurface *QRuntimeGraphicsSystem::createWindowSurface(QWidget *widget) const +{ + Q_ASSERT(m_graphicsSystem); + QRuntimeWindowSurface *rtSurface = new QRuntimeWindowSurface(this, widget); + rtSurface->m_windowSurface = m_graphicsSystem->createWindowSurface(widget); + widget->setWindowSurface(rtSurface); + m_windowSurfaces << rtSurface; + increaseMemoryUsage(rtSurface->memoryUsage()); + return rtSurface; +} + +/*! + Sets graphics system when resource memory consumption is under /a memoryUsageLimit. +*/ +void QRuntimeGraphicsSystem::setGraphicsSystem(const QString &name, uint memoryUsageLimit) +{ +#ifdef QT_DEBUG + qDebug() << "QRuntimeGraphicsSystem::setGraphicsSystem( "<< name <<", " << memoryUsageLimit << ")"; + qDebug() << " current approximated graphics system memory usage " << memoryUsage() << " bytes"; +#endif + if (memoryUsage() >= memoryUsageLimit) { + m_graphicsSystemChangeMemoryLimit = memoryUsageLimit; + m_pendingGraphicsSystemName = name; + } else { + setGraphicsSystem(name); + } +} + +void QRuntimeGraphicsSystem::setGraphicsSystem(const QString &name) +{ + if (m_graphicsSystemName == name) + return; +#ifdef QT_DEBUG + qDebug() << "QRuntimeGraphicsSystem::setGraphicsSystem( " << name << " )"; + qDebug() << " current approximated graphics system memory usage "<< memoryUsage() << " bytes"; +#endif + delete m_graphicsSystem; + m_graphicsSystem = QGraphicsSystemFactory::create(name); + m_graphicsSystemName = name; + + Q_ASSERT(m_graphicsSystem); + + m_graphicsSystemChangeMemoryLimit = 0; + m_pendingGraphicsSystemName = QString(); + + for (int i = 0; i < m_pixmapDatas.size(); ++i) { + QRuntimePixmapData *proxy = m_pixmapDatas.at(i); + QPixmapData *newData = m_graphicsSystem->createPixmapData(proxy->m_data->pixelType()); + // ### TODO Optimize. Openvg and s60raster graphics systems could switch internal ARGB32_PRE QImage buffers. + newData->fromImage(proxy->m_data->toImage(), Qt::AutoColor | Qt::OrderedAlphaDither); + delete proxy->m_data; + proxy->m_data = newData; + proxy->readBackInfo(); + } + + for (int i = 0; i < m_windowSurfaces.size(); ++i) { + QRuntimeWindowSurface *proxy = m_windowSurfaces.at(i); + QWidget *widget = proxy->m_windowSurface->window(); + + if(m_windowSurfaceDestroyPolicy == DestroyImmediately) { + delete proxy->m_windowSurface; + proxy->m_pendingWindowSurface = 0; + } else { + proxy->m_pendingWindowSurface = proxy->m_windowSurface; + } + + proxy->m_windowSurface = m_graphicsSystem->createWindowSurface(widget); + qt_widget_private(widget)->invalidateBuffer(widget->rect()); + } +} + +void QRuntimeGraphicsSystem::removePixmapData(QRuntimePixmapData *pixmapData) const +{ + int index = m_pixmapDatas.lastIndexOf(pixmapData); + m_pixmapDatas.removeAt(index); + decreaseMemoryUsage(pixmapData->memoryUsage(), true); +} + +void QRuntimeGraphicsSystem::removeWindowSurface(QRuntimeWindowSurface *windowSurface) const +{ + int index = m_windowSurfaces.lastIndexOf(windowSurface); + m_windowSurfaces.removeAt(index); + decreaseMemoryUsage(windowSurface->memoryUsage(), true); +} + +void QRuntimeGraphicsSystem::increaseMemoryUsage(uint amount) const +{ + m_memoryUsage += amount; + + if (m_graphicsSystemChangeMemoryLimit && + m_memoryUsage < m_graphicsSystemChangeMemoryLimit) { + + QRuntimeGraphicsSystem *gs = const_cast<QRuntimeGraphicsSystem*>(this); + QDeferredGraphicsSystemChange *deferredChange = + new QDeferredGraphicsSystemChange(gs, m_pendingGraphicsSystemName); + deferredChange->launch(); + } +} + +void QRuntimeGraphicsSystem::decreaseMemoryUsage(uint amount, bool persistent) const +{ + m_memoryUsage -= amount; + + if (persistent && m_graphicsSystemChangeMemoryLimit && + m_memoryUsage < m_graphicsSystemChangeMemoryLimit) { + + QRuntimeGraphicsSystem *gs = const_cast<QRuntimeGraphicsSystem*>(this); + QDeferredGraphicsSystemChange *deferredChange = + new QDeferredGraphicsSystemChange(gs, m_pendingGraphicsSystemName); + deferredChange->launch(); + } +} + +#include "qgraphicssystem_runtime.moc" + +QT_END_NAMESPACE diff --git a/src/gui/painting/qgraphicssystem_runtime_p.h b/src/gui/painting/qgraphicssystem_runtime_p.h new file mode 100644 index 0000000..445f83d --- /dev/null +++ b/src/gui/painting/qgraphicssystem_runtime_p.h @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 QGRAPHICSSYSTEM_RUNTIME_P_H +#define QGRAPHICSSYSTEM_RUNTIME_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qgraphicssystem_p.h" + +#include <private/qpixmapdata_p.h> + +QT_BEGIN_NAMESPACE + +class QRuntimeGraphicsSystem; + +class QRuntimePixmapData : public QPixmapData { +public: + QRuntimePixmapData(const QRuntimeGraphicsSystem *gs, PixelType type); + ~QRuntimePixmapData(); + + virtual QPixmapData *createCompatiblePixmapData() const; + virtual void resize(int width, int height); + virtual void fromImage(const QImage &image, + Qt::ImageConversionFlags flags); + + virtual bool fromFile(const QString &filename, const char *format, + Qt::ImageConversionFlags flags); + virtual bool fromData(const uchar *buffer, uint len, const char *format, + Qt::ImageConversionFlags flags); + + virtual void copy(const QPixmapData *data, const QRect &rect); + virtual bool scroll(int dx, int dy, const QRect &rect); + + virtual int metric(QPaintDevice::PaintDeviceMetric metric) const; + virtual void fill(const QColor &color); + virtual QBitmap mask() const; + virtual void setMask(const QBitmap &mask); + virtual bool hasAlphaChannel() const; + virtual QPixmap transformed(const QTransform &matrix, + Qt::TransformationMode mode) const; + virtual void setAlphaChannel(const QPixmap &alphaChannel); + virtual QPixmap alphaChannel() const; + virtual QImage toImage() const; + virtual QPaintEngine *paintEngine() const; + + virtual QImage *buffer(); + + void readBackInfo(); + + QPixmapData *m_data; + +#if defined(Q_OS_SYMBIAN) + void* toNativeType(NativeType type); + void fromNativeType(void* pixmap, NativeType type); +#endif + + virtual QPixmapData *runtimeData() const; + + virtual uint memoryUsage() const; + +private: + const QRuntimeGraphicsSystem *m_graphicsSystem; + +}; + +class QRuntimeWindowSurface : public QWindowSurface { +public: + QRuntimeWindowSurface(const QRuntimeGraphicsSystem *gs, QWidget *window); + ~QRuntimeWindowSurface(); + + virtual QPaintDevice *paintDevice(); + virtual void flush(QWidget *widget, const QRegion ®ion, + const QPoint &offset); + virtual void setGeometry(const QRect &rect); + + virtual bool scroll(const QRegion &area, int dx, int dy); + + virtual void beginPaint(const QRegion &); + virtual void endPaint(const QRegion &); + + virtual QImage* buffer(const QWidget *widget); + virtual QPixmap grabWidget(const QWidget *widget, const QRect& rectangle = QRect()) const; + + virtual QPoint offset(const QWidget *widget) const; + + virtual uint memoryUsage() const; + + QWindowSurface *m_windowSurface; + QWindowSurface *m_pendingWindowSurface; + +private: + const QRuntimeGraphicsSystem *m_graphicsSystem; +}; + +class QRuntimeGraphicsSystem : public QGraphicsSystem +{ +public: + + enum WindowSurfaceDestroyPolicy + { + DestroyImmediately, + DestroyAfterFirstFlush + }; + +public: + QRuntimeGraphicsSystem(); + + QPixmapData *createPixmapData(QPixmapData::PixelType type) const; + QWindowSurface *createWindowSurface(QWidget *widget) const; + + void removePixmapData(QRuntimePixmapData *pixmapData) const; + void removeWindowSurface(QRuntimeWindowSurface *windowSurface) const; + + void setGraphicsSystem(const QString &name, uint memoryUsageLimit); + void setGraphicsSystem(const QString &name); + QString graphicsSystemName() const { return m_graphicsSystemName; } + + void setWindowSurfaceDestroyPolicy(WindowSurfaceDestroyPolicy policy) + { + m_windowSurfaceDestroyPolicy = policy; + } + + int windowSurfaceDestroyPolicy() const { return m_windowSurfaceDestroyPolicy; } + + int memoryUsage() const { return m_memoryUsage; } + +private: + + void increaseMemoryUsage(uint amount) const; + void decreaseMemoryUsage(uint amount, bool persistent = false) const; + +private: + mutable uint m_memoryUsage; + int m_windowSurfaceDestroyPolicy; + QGraphicsSystem *m_graphicsSystem; + mutable QList<QRuntimePixmapData *> m_pixmapDatas; + mutable QList<QRuntimeWindowSurface *> m_windowSurfaces; + QString m_graphicsSystemName; + + uint m_graphicsSystemChangeMemoryLimit; + QString m_pendingGraphicsSystemName; + + friend class QRuntimePixmapData; + friend class QRuntimeWindowSurface; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/gui/painting/qgraphicssystemfactory.cpp b/src/gui/painting/qgraphicssystemfactory.cpp index 3c09894..ee6fbd8 100644 --- a/src/gui/painting/qgraphicssystemfactory.cpp +++ b/src/gui/painting/qgraphicssystemfactory.cpp @@ -46,6 +46,7 @@ #include "qapplication.h" #include "qgraphicssystem_raster_p.h" +#include "qgraphicssystem_runtime_p.h" #include "qdebug.h" QT_BEGIN_NAMESPACE @@ -68,6 +69,10 @@ QGraphicsSystem *QGraphicsSystemFactory::create(const QString& key) if (system.isEmpty()) { system = QLatin1String("openvg"); } +#elif defined (QT_GRAPHICSSYSTEM_RUNTIME) + if (system.isEmpty()) { + system = QLatin1String("runtime"); + } #elif defined (QT_GRAPHICSSYSTEM_RASTER) && !defined(Q_WS_WIN) && !defined(Q_OS_SYMBIAN) if (system.isEmpty()) { system = QLatin1String("raster"); @@ -76,6 +81,8 @@ QGraphicsSystem *QGraphicsSystemFactory::create(const QString& key) if (system == QLatin1String("raster")) return new QRasterGraphicsSystem; + else if (system == QLatin1String("runtime")) + return new QRuntimeGraphicsSystem; else if (system.isEmpty() || system == QLatin1String("native")) return 0; diff --git a/src/gui/painting/qgrayraster.c b/src/gui/painting/qgrayraster.c index ff2469c..5e7c67a 100644 --- a/src/gui/painting/qgrayraster.c +++ b/src/gui/painting/qgrayraster.c @@ -156,6 +156,7 @@ #define ErrRaster_Invalid_Outline -1 #define ErrRaster_Invalid_Argument -3 #define ErrRaster_Memory_Overflow -4 +#define ErrRaster_OutOfMemory -6 #define QT_FT_BEGIN_HEADER #define QT_FT_END_HEADER @@ -222,7 +223,6 @@ #define DOWNSCALE( x ) ( (x) << ( 6 - PIXEL_BITS ) ) #endif - /*************************************************************************/ /* */ /* TYPE DEFINITIONS */ @@ -1757,8 +1757,7 @@ #ifdef DEBUG_GRAYS fprintf( stderr, "Rotten glyph!\n" ); #endif - /* == Raster_Err_OutOfMemory in qblackraster.c */ - return -6; + return ErrRaster_OutOfMemory; } if ( bottom-top >= ras.band_size ) @@ -1784,7 +1783,7 @@ static int - gray_raster_render( PRaster raster, + gray_raster_render( QT_FT_Raster raster, const QT_FT_Raster_Params* params ) { const QT_FT_Outline* outline = (const QT_FT_Outline*)params->source; @@ -1795,6 +1794,12 @@ if ( !raster || !raster->buffer || !raster->buffer_size ) return ErrRaster_Invalid_Argument; + // If raster object and raster buffer are allocated, but + // raster size isn't of the minimum size, indicate out of + // memory. + if (raster && raster->buffer && raster->buffer_size < MINIMUM_POOL_SIZE ) + return ErrRaster_OutOfMemory; + /* return immediately if the outline is empty */ if ( outline->n_points == 0 || outline->n_contours <= 0 ) return 0; @@ -1874,19 +1879,15 @@ /**** a static object. *****/ static int - gray_raster_new( void * memory, - QT_FT_Raster* araster ) + gray_raster_new( QT_FT_Raster* araster ) { - if (memory) - fprintf(stderr, "gray_raster_new(), memory ignored"); - memory = malloc(sizeof(TRaster)); - if (!memory) { + *araster = malloc(sizeof(TRaster)); + if (!*araster) { *araster = 0; return ErrRaster_Memory_Overflow; } - QT_FT_MEM_ZERO(memory, sizeof(TRaster)); + QT_FT_MEM_ZERO(*araster, sizeof(TRaster)); - *araster = (QT_FT_Raster) memory; return 0; } @@ -1905,10 +1906,9 @@ { PRaster rast = (PRaster)raster; - if ( raster ) { - if ( pool_base && pool_size >= (long)sizeof ( TWorker ) + 2048 ) + if ( pool_base && ( pool_size >= MINIMUM_POOL_SIZE ) ) { PWorker worker = (PWorker)pool_base; @@ -1923,6 +1923,13 @@ rast->band_size = (int)( rast->buffer_size / ( sizeof ( TCell ) * 8 ) ); } + else if ( pool_base) + { // Case when there is a raster pool allocated, but it + // doesn't have the minimum size (and so memory will be reallocated) + rast->buffer = pool_base; + rast->worker = NULL; + rast->buffer_size = pool_size; + } else { rast->buffer = NULL; diff --git a/src/gui/painting/qgrayraster_p.h b/src/gui/painting/qgrayraster_p.h index 4463fc9..ad595b8 100644 --- a/src/gui/painting/qgrayraster_p.h +++ b/src/gui/painting/qgrayraster_p.h @@ -89,6 +89,10 @@ #define QT_FT_EXPORT_VAR( x ) extern x #endif +/* Minimum buffer size for raster object, that accounts + for TWorker and TCell sizes.*/ +#define MINIMUM_POOL_SIZE 4096 + QT_FT_EXPORT_VAR( const QT_FT_Raster_Funcs ) qt_ft_grays_raster; diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp index 00f32f7..7746316 100644 --- a/src/gui/painting/qmatrix.cpp +++ b/src/gui/painting/qmatrix.cpp @@ -103,7 +103,7 @@ QT_BEGIN_NAMESPACE coordinate system. The standard coordinate system of a QPaintDevice has its origin located at the top-left position. The \e x values increase to the right; \e y values increase - downward. For a complete description, see the \l {The Coordinate + downward. For a complete description, see the \l {Coordinate System}{coordinate system} documentation. QPainter has functions to translate, scale, shear and rotate the @@ -176,7 +176,7 @@ QT_BEGIN_NAMESPACE \snippet doc/src/snippets/matrix/matrix.cpp 2 \endtable - \sa QPainter, QTransform, {The Coordinate System}, + \sa QPainter, QTransform, {Coordinate System}, {demos/affine}{Affine Transformations Demo}, {Transformations Example} */ @@ -1135,7 +1135,7 @@ Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m) Writes the given \a matrix to the given \a stream and returns a reference to the stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &s, const QMatrix &m) @@ -1161,7 +1161,7 @@ QDataStream &operator<<(QDataStream &s, const QMatrix &m) Reads the given \a matrix from the given \a stream and returns a reference to the stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &s, QMatrix &m) diff --git a/src/gui/painting/qoutlinemapper.cpp b/src/gui/painting/qoutlinemapper.cpp index ad0c2eb..bf03545 100644 --- a/src/gui/painting/qoutlinemapper.cpp +++ b/src/gui/painting/qoutlinemapper.cpp @@ -154,7 +154,8 @@ QT_FT_Outline *QOutlineMapper::convertPath(const QVectorPath &path) // ### We can kill this copying and just use the buffer straight... m_elements.resize(count); - memcpy(m_elements.data(), path.points(), count* sizeof(QPointF)); + if (count) + memcpy(m_elements.data(), path.points(), count* sizeof(QPointF)); m_element_types.resize(0); } @@ -233,12 +234,12 @@ void QOutlineMapper::endOutline() // Check for out of dev bounds... - const bool do_clip = (controlPointRect.left() < -QT_RASTER_COORD_LIMIT + const bool do_clip = !m_in_clip_elements && ((controlPointRect.left() < -QT_RASTER_COORD_LIMIT || controlPointRect.right() > QT_RASTER_COORD_LIMIT || controlPointRect.top() < -QT_RASTER_COORD_LIMIT || controlPointRect.bottom() > QT_RASTER_COORD_LIMIT || controlPointRect.width() > QT_RASTER_COORD_LIMIT - || controlPointRect.height() > QT_RASTER_COORD_LIMIT); + || controlPointRect.height() > QT_RASTER_COORD_LIMIT)); if (do_clip) { clipElements(elements, elementTypes(), element_count); @@ -352,7 +353,13 @@ void QOutlineMapper::clipElements(const QPointF *elements, // instead of going through convenience functionallity, but since // this part of code hardly every used, it shouldn't matter. + m_in_clip_elements = true; + QPainterPath path; + + if (!(m_outline.flags & QT_FT_OUTLINE_EVEN_ODD_FILL)) + path.setFillRule(Qt::WindingFill); + if (types) { for (int i=0; i<element_count; ++i) { switch (types[i]) { @@ -388,6 +395,8 @@ void QOutlineMapper::clipElements(const QPointF *elements, else convertPath(clippedPath); m_txop = old_txop; + + m_in_clip_elements = false; } QT_END_NAMESPACE diff --git a/src/gui/painting/qoutlinemapper_p.h b/src/gui/painting/qoutlinemapper_p.h index d0ce1a9..f64d03b 100644 --- a/src/gui/painting/qoutlinemapper_p.h +++ b/src/gui/painting/qoutlinemapper_p.h @@ -87,8 +87,16 @@ const int QT_RASTER_COORD_LIMIT = 32767; class QOutlineMapper { public: - QOutlineMapper() - : m_round_coords(false) + QOutlineMapper() : + m_element_types(0), + m_elements(0), + m_elements_dev(0), + m_points(0), + m_tags(0), + m_contours(0), + m_polygon_dev(0), + m_round_coords(false), + m_in_clip_elements(false) { } @@ -228,6 +236,7 @@ public: qreal m_dy; bool m_valid; + bool m_in_clip_elements; private: bool m_round_coords; diff --git a/src/gui/painting/qpaintdevice.qdoc b/src/gui/painting/qpaintdevice.qdoc index 8c73cc0..340db39 100644 --- a/src/gui/painting/qpaintdevice.qdoc +++ b/src/gui/painting/qpaintdevice.qdoc @@ -87,8 +87,7 @@ function returns the number of different colors available for the paint device. - \sa QPaintEngine, QPainter, {The Coordinate System}, {The Paint - System} + \sa QPaintEngine, QPainter, {Coordinate System}, {Paint System} */ /*! diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index 6aabde8..a2d0337 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -172,7 +172,7 @@ QFont QTextItem::font() const possible to adapt to multiple technologies on each platform and take advantage of each to the fullest. - \sa QPainter, QPaintDevice::paintEngine(), {The Paint System} + \sa QPainter, QPaintDevice::paintEngine(), {Paint System} */ /*! diff --git a/src/gui/painting/qpaintengine_mac.cpp b/src/gui/painting/qpaintengine_mac.cpp index 14ba94e..e5323d8 100644 --- a/src/gui/painting/qpaintengine_mac.cpp +++ b/src/gui/painting/qpaintengine_mac.cpp @@ -1390,7 +1390,11 @@ QCoreGraphicsPaintEngine::updateRenderHints(QPainter::RenderHints hints) CGContextSetInterpolationQuality(d->hd, (hints & QPainter::SmoothPixmapTransform) ? kCGInterpolationHigh : kCGInterpolationNone); } - CGContextSetShouldSmoothFonts(d->hd, hints & QPainter::TextAntialiasing); + bool textAntialiasing = (hints & QPainter::TextAntialiasing) == QPainter::TextAntialiasing; + if (!textAntialiasing || d->disabledSmoothFonts) { + d->disabledSmoothFonts = !textAntialiasing; + CGContextSetShouldSmoothFonts(d->hd, textAntialiasing); + } } /* diff --git a/src/gui/painting/qpaintengine_mac_p.h b/src/gui/painting/qpaintengine_mac_p.h index c9ab419..940b2bc 100644 --- a/src/gui/painting/qpaintengine_mac_p.h +++ b/src/gui/painting/qpaintengine_mac_p.h @@ -148,7 +148,7 @@ class QCoreGraphicsPaintEnginePrivate : public QPaintEnginePrivate Q_DECLARE_PUBLIC(QCoreGraphicsPaintEngine) public: QCoreGraphicsPaintEnginePrivate() - : hd(0), shading(0), stackCount(0), complexXForm(false) + : hd(0), shading(0), stackCount(0), complexXForm(false), disabledSmoothFonts(false) { } @@ -168,6 +168,7 @@ public: CGShadingRef shading; int stackCount; bool complexXForm; + bool disabledSmoothFonts; enum { CosmeticNone, CosmeticTransformPath, CosmeticSetPenWidth } cosmeticPen; // pixel and cosmetic pen size in user coordinates. diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 6afa4e1..4fad0c6 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -68,6 +68,7 @@ // #include <private/qrasterizer_p.h> #include <private/qimage_p.h> #include <private/qstatictext_p.h> +#include "qmemrotate_p.h" #include "qpaintengine_raster_p.h" // #include "qbezier_p.h" @@ -253,6 +254,11 @@ static void qt_debug_path(const QPainterPath &path) } #endif +QRasterPaintEnginePrivate::QRasterPaintEnginePrivate() : + QPaintEngineExPrivate(), + cachedLines(0) +{ +} /*! @@ -338,26 +344,13 @@ void QRasterPaintEngine::init() d->hdc = 0; #endif - d->rasterPoolSize = 8192; - d->rasterPoolBase = -#if defined(Q_WS_WIN64) - // We make use of setjmp and longjmp in qgrayraster.c which requires - // 16-byte alignment, hence we hardcode this requirement here.. - (unsigned char *) _aligned_malloc(d->rasterPoolSize, sizeof(void*) * 2); -#else - (unsigned char *) malloc(d->rasterPoolSize); -#endif - Q_CHECK_PTR(d->rasterPoolBase); - // The antialiasing raster. d->grayRaster.reset(new QT_FT_Raster); Q_CHECK_PTR(d->grayRaster.data()); - if (qt_ft_grays_raster.raster_new(0, d->grayRaster.data())) + if (qt_ft_grays_raster.raster_new(d->grayRaster.data())) QT_THROW(std::bad_alloc()); // an error creating the raster is caused by a bad malloc - qt_ft_grays_raster.raster_reset(*d->grayRaster.data(), d->rasterPoolBase, d->rasterPoolSize); - d->rasterizer.reset(new QRasterizer); d->rasterBuffer.reset(new QRasterBuffer()); d->outlineMapper.reset(new QOutlineMapper); @@ -439,12 +432,6 @@ QRasterPaintEngine::~QRasterPaintEngine() { Q_D(QRasterPaintEngine); -#if defined(Q_WS_WIN64) - _aligned_free(d->rasterPoolBase); -#else - free(d->rasterPoolBase); -#endif - qt_ft_grays_raster.raster_done(*d->grayRaster.data()); } @@ -457,8 +444,9 @@ bool QRasterPaintEngine::begin(QPaintDevice *device) if (device->devType() == QInternal::Pixmap) { QPixmap *pixmap = static_cast<QPixmap *>(device); - if (pixmap->data->classId() == QPixmapData::RasterClass || pixmap->data->classId() == QPixmapData::BlitterClass) - d->device = pixmap->data->buffer(); + QPixmapData *pd = pixmap->pixmapData(); + if (pd->classId() == QPixmapData::RasterClass || pd->classId() == QPixmapData::BlitterClass) + d->device = pd->buffer(); } else { d->device = device; } @@ -473,13 +461,12 @@ bool QRasterPaintEngine::begin(QPaintDevice *device) QRasterPaintEngineState *s = state(); ensureOutlineMapper(); - d->outlineMapper->m_clip_rect = d->deviceRect.adjusted(-10, -10, 10, 10); - - // This is the upp - QRect bounds(-QT_RASTER_COORD_LIMIT, -QT_RASTER_COORD_LIMIT, - QT_RASTER_COORD_LIMIT*2 - 1, QT_RASTER_COORD_LIMIT * 2 - 1); - d->outlineMapper->m_clip_rect = bounds.intersected(d->outlineMapper->m_clip_rect); + d->outlineMapper->m_clip_rect = d->deviceRect; + if (d->outlineMapper->m_clip_rect.width() > QT_RASTER_COORD_LIMIT) + d->outlineMapper->m_clip_rect.setWidth(QT_RASTER_COORD_LIMIT); + if (d->outlineMapper->m_clip_rect.height() > QT_RASTER_COORD_LIMIT) + d->outlineMapper->m_clip_rect.setHeight(QT_RASTER_COORD_LIMIT); d->rasterizer->setClipRect(d->deviceRect); @@ -2374,8 +2361,9 @@ void QRasterPaintEngine::drawPixmap(const QPointF &pos, const QPixmap &pixmap) qDebug() << " - QRasterPaintEngine::drawPixmap(), pos=" << pos << " pixmap=" << pixmap.size() << "depth=" << pixmap.depth(); #endif - if (pixmap.data->classId() == QPixmapData::RasterClass) { - const QImage &image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image; + QPixmapData *pd = pixmap.pixmapData(); + if (pd->classId() == QPixmapData::RasterClass) { + const QImage &image = static_cast<QRasterPixmapData *>(pd)->image; if (image.depth() == 1) { Q_D(QRasterPaintEngine); QRasterPaintEngineState *s = state(); @@ -2414,8 +2402,9 @@ void QRasterPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pixmap, cons qDebug() << " - QRasterPaintEngine::drawPixmap(), r=" << r << " sr=" << sr << " pixmap=" << pixmap.size() << "depth=" << pixmap.depth(); #endif - if (pixmap.data->classId() == QPixmapData::RasterClass) { - const QImage &image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image; + QPixmapData* pd = pixmap.pixmapData(); + if (pd->classId() == QPixmapData::RasterClass) { + const QImage &image = static_cast<QRasterPixmapData *>(pd)->image; if (image.depth() == 1) { Q_D(QRasterPaintEngine); QRasterPaintEngineState *s = state(); @@ -2534,6 +2523,58 @@ QRectF qt_mapRect_non_normalizing(const QRectF &r, const QTransform &t) return QRectF(r.topLeft() * t, r.bottomRight() * t); } +namespace { + enum RotationType { + Rotation90, + Rotation180, + Rotation270, + NoRotation + }; + + inline RotationType qRotationType(const QTransform &transform) + { + QTransform::TransformationType type = transform.type(); + + if (type > QTransform::TxRotate) + return NoRotation; + + if (type == QTransform::TxRotate && qFuzzyIsNull(transform.m11()) && qFuzzyCompare(transform.m12(), qreal(-1)) + && qFuzzyCompare(transform.m21(), qreal(1)) && qFuzzyIsNull(transform.m22())) + return Rotation90; + + if (type == QTransform::TxScale && qFuzzyCompare(transform.m11(), qreal(-1)) && qFuzzyIsNull(transform.m12()) + && qFuzzyIsNull(transform.m21()) && qFuzzyCompare(transform.m22(), qreal(-1))) + return Rotation180; + + if (type == QTransform::TxRotate && qFuzzyIsNull(transform.m11()) && qFuzzyCompare(transform.m12(), qreal(1)) + && qFuzzyCompare(transform.m21(), qreal(-1)) && qFuzzyIsNull(transform.m22())) + return Rotation270; + + return NoRotation; + } + + template <typename T> void memRotate(RotationType type, const T *srcBase, int w, int h, int sbpl, T *dstBase, int dbpl) + { + switch (type) { + case Rotation90: + qt_memrotate90(srcBase, w, h, sbpl, dstBase, dbpl); + break; + case Rotation180: + qt_memrotate180(srcBase, w, h, sbpl, dstBase, dbpl); + break; + case Rotation270: + qt_memrotate270(srcBase, w, h, sbpl, dstBase, dbpl); + break; + case NoRotation: + break; + } + } + + inline bool isPixelAligned(const QRectF &rect) { + return QRectF(rect.toRect()) == rect; + } +} + /*! \reimp */ @@ -2595,6 +2636,58 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe const QClipData *clip = d->clip(); + if (s->matrix.type() > QTransform::TxTranslate + && !stretch_sr + && (!clip || clip->hasRectClip) + && s->intOpacity == 256 + && (d->rasterBuffer->compositionMode == QPainter::CompositionMode_SourceOver + || d->rasterBuffer->compositionMode == QPainter::CompositionMode_Source) + && d->rasterBuffer->format == img.format() + && (d->rasterBuffer->format == QImage::Format_RGB16 + || d->rasterBuffer->format == QImage::Format_RGB32 + || (d->rasterBuffer->format == QImage::Format_ARGB32_Premultiplied + && d->rasterBuffer->compositionMode == QPainter::CompositionMode_Source))) + { + RotationType rotationType = qRotationType(s->matrix); + + if (rotationType != NoRotation && img.rect().contains(sr.toAlignedRect())) { + QRectF transformedTargetRect = s->matrix.mapRect(r); + + if ((!(s->renderHints & QPainter::SmoothPixmapTransform) && !(s->renderHints & QPainter::Antialiasing)) + || (isPixelAligned(transformedTargetRect) && isPixelAligned(sr))) + { + QRect clippedTransformedTargetRect = transformedTargetRect.toRect().intersected(clip ? clip->clipRect : d->deviceRect); + if (clippedTransformedTargetRect.isNull()) + return; + + QRectF clippedTargetRect = s->matrix.inverted().mapRect(QRectF(clippedTransformedTargetRect)); + + QRect clippedSourceRect + = QRectF(sr.x() + clippedTargetRect.x() - r.x(), sr.y() + clippedTargetRect.y() - r.y(), + clippedTargetRect.width(), clippedTargetRect.height()).toRect(); + + uint dbpl = d->rasterBuffer->bytesPerLine(); + uint sbpl = img.bytesPerLine(); + + uchar *dst = d->rasterBuffer->buffer(); + uint bpp = img.depth() >> 3; + + const uchar *srcBase = img.bits() + clippedSourceRect.y() * sbpl + clippedSourceRect.x() * bpp; + uchar *dstBase = dst + clippedTransformedTargetRect.y() * dbpl + clippedTransformedTargetRect.x() * bpp; + + uint cw = clippedSourceRect.width(); + uint ch = clippedSourceRect.height(); + + if (d->rasterBuffer->format == QImage::Format_RGB16) + memRotate(rotationType, (quint16 *)srcBase, cw, ch, sbpl, (quint16 *)dstBase, dbpl); + else + memRotate(rotationType, (quint32 *)srcBase, cw, ch, sbpl, (quint32 *)dstBase, dbpl); + + return; + } + } + } + if (s->matrix.type() > QTransform::TxTranslate || stretch_sr) { if (s->flags.fast_images) { @@ -2719,8 +2812,9 @@ void QRasterPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, QImage image; - if (pixmap.data->classId() == QPixmapData::RasterClass) { - image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image; + QPixmapData *pd = pixmap.pixmapData(); + if (pd->classId() == QPixmapData::RasterClass) { + image = static_cast<QRasterPixmapData *>(pd)->image; } else { image = pixmap.toImage(); } @@ -3696,6 +3790,7 @@ void QRasterPaintEngine::drawEllipse(const QRectF &rect) if (((qpen_style(s->lastPen) == Qt::SolidLine && s->flags.fast_pen) || (qpen_style(s->lastPen) == Qt::NoPen && !s->flags.antialiased)) && qMax(rect.width(), rect.height()) < QT_RASTER_COORD_LIMIT + && !rect.isEmpty() && s->matrix.type() <= QTransform::TxScale) // no shear { ensureBrush(); @@ -4092,6 +4187,26 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, return; } + // Initial size for raster pool is MINIMUM_POOL_SIZE so as to + // minimize memory reallocations. However if initial size for + // raster pool is changed for lower value, reallocations will + // occur normally. + const int rasterPoolInitialSize = MINIMUM_POOL_SIZE; + int rasterPoolSize = rasterPoolInitialSize; + unsigned char *rasterPoolBase; +#if defined(Q_WS_WIN64) + rasterPoolBase = + // We make use of setjmp and longjmp in qgrayraster.c which requires + // 16-byte alignment, hence we hardcode this requirement here.. + (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2); +#else + unsigned char rasterPoolOnStack[rasterPoolInitialSize]; + rasterPoolBase = rasterPoolOnStack; +#endif + Q_CHECK_PTR(rasterPoolBase); + + qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize); + void *data = userData; QT_FT_BBox clip_box = { deviceRect.x(), @@ -4120,17 +4235,18 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, error = qt_ft_grays_raster.raster_render(*grayRaster.data(), &rasterParams); // Out of memory, reallocate some more and try again... - if (error == -6) { // -6 is Result_err_OutOfMemory + if (error == -6) { // ErrRaster_OutOfMemory from qgrayraster.c int new_size = rasterPoolSize * 2; if (new_size > 1024 * 1024) { qWarning("QPainter: Rasterization of primitive failed"); - return; + break; } #if defined(Q_WS_WIN64) _aligned_free(rasterPoolBase); #else - free(rasterPoolBase); + if (rasterPoolBase != rasterPoolOnStack) // initially on the stack + free(rasterPoolBase); #endif rasterPoolSize = new_size; @@ -4145,12 +4261,19 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, Q_CHECK_PTR(rasterPoolBase); // note: we just freed the old rasterPoolBase. I hope it's not fatal. qt_ft_grays_raster.raster_done(*grayRaster.data()); - qt_ft_grays_raster.raster_new(0, grayRaster.data()); + qt_ft_grays_raster.raster_new(grayRaster.data()); qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize); } else { done = true; } } + +#if defined(Q_WS_WIN64) + _aligned_free(rasterPoolBase); +#else + if (rasterPoolBase != rasterPoolOnStack) // initially on the stack + free(rasterPoolBase); +#endif } void QRasterPaintEnginePrivate::recalculateFastImages() diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h index a21560c..fd635e6 100644 --- a/src/gui/painting/qpaintengine_raster_p.h +++ b/src/gui/painting/qpaintengine_raster_p.h @@ -302,6 +302,7 @@ QRasterPaintEnginePrivate : public QPaintEngineExPrivate { Q_DECLARE_PUBLIC(QRasterPaintEngine) public: + QRasterPaintEnginePrivate(); void rasterizeLine_dashed(QLineF line, qreal width, int *dashIndex, qreal *dashOffset, bool *inDash); @@ -356,8 +357,6 @@ public: QScopedPointer<QDashStroker> dashStroker; QScopedPointer<QT_FT_Raster> grayRaster; - unsigned long rasterPoolSize; - unsigned char *rasterPoolBase; QDataBuffer<QLineF> cachedLines; QSpanData image_filler; diff --git a/src/gui/painting/qpaintengine_x11.cpp b/src/gui/painting/qpaintengine_x11.cpp index da48fcb..910b2df 100644 --- a/src/gui/painting/qpaintengine_x11.cpp +++ b/src/gui/painting/qpaintengine_x11.cpp @@ -79,6 +79,8 @@ #include <private/qtessellator_p.h> #endif +#include <private/qstylehelper_p.h> + QT_BEGIN_NAMESPACE extern Drawable qt_x11Handle(const QPaintDevice *pd); @@ -224,7 +226,10 @@ static const uchar base_dither_matrix[DITHER_SIZE][DITHER_SIZE] = { static QPixmap qt_patternForAlpha(uchar alpha, int screen) { QPixmap pm; - QString key = QLatin1String("$qt-alpha-brush$") + QString::number(alpha) + QString::number(screen); + QString key = QLatin1Literal("$qt-alpha-brush$") + % HexString<uchar>(alpha) + % HexString<int>(screen); + if (!QPixmapCache::find(key, pm)) { // #### why not use a mono image here???? QImage pattern(DITHER_SIZE, DITHER_SIZE, QImage::Format_ARGB32); @@ -315,7 +320,7 @@ static Picture getPatternFill(int screen, const QBrush &b) return X11->pattern_fills[i].picture; } // none found, replace one - int i = rand() % 16; + int i = qrand() % 16; if (X11->pattern_fills[i].screen != screen && X11->pattern_fills[i].picture) { XRenderFreePicture (X11->display, X11->pattern_fills[i].picture); @@ -1448,6 +1453,11 @@ void QX11PaintEngine::drawEllipse(const QRectF &rect) void QX11PaintEngine::drawEllipse(const QRect &rect) { + if (rect.isEmpty()) { + drawRects(&rect, 1); + return; + } + Q_D(QX11PaintEngine); QRect devclip(SHRT_MIN, SHRT_MIN, SHRT_MAX*2 - 1, SHRT_MAX*2 - 1); QRect r(rect); diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index a78cafb..e0746fb 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -149,6 +149,7 @@ QDebug Q_GUI_EXPORT &operator<<(QDebug &s, const QVectorPath &path) struct StrokeHandler { + StrokeHandler(int reserve) : pts(reserve), types(reserve) {} QDataBuffer<qreal> pts; QDataBuffer<QPainterPath::ElementType> types; }; @@ -394,7 +395,7 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) return; if (!d->strokeHandler) { - d->strokeHandler = new StrokeHandler; + d->strokeHandler = new StrokeHandler(path.elementCount()+4); d->stroker.setMoveToHook(qpaintengineex_moveTo); d->stroker.setLineToHook(qpaintengineex_lineTo); d->stroker.setCubicToHook(qpaintengineex_cubicTo); @@ -460,6 +461,7 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) // change the current transform. Normal transformed, // non-cosmetic pens will be transformed as part of fill // later, so they are also covered here.. + d->activeStroker->setCurveThresholdFromTransform(state()->matrix); d->activeStroker->begin(d->strokeHandler); if (types) { while (points < lastPoint) { @@ -492,11 +494,9 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) } else { d->activeStroker->moveTo(points[0], points[1]); points += 2; - ++types; while (points < lastPoint) { d->activeStroker->lineTo(points[0], points[1]); points += 2; - ++types; } if (path.hasImplicitClose()) d->activeStroker->lineTo(path.points()[0], path.points()[1]); @@ -517,6 +517,7 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) QPainterPath painterPath = state()->matrix.map(path.convertToPainterPath()); d->activeStroker->strokePath(painterPath, d->strokeHandler, QTransform()); } else { + d->activeStroker->setCurveThresholdFromTransform(state()->matrix); d->activeStroker->begin(d->strokeHandler); if (types) { while (points < lastPoint) { @@ -558,12 +559,10 @@ void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) QPointF p = ((QPointF *)points)[0] * state()->matrix; d->activeStroker->moveTo(p.x(), p.y()); points += 2; - ++types; while (points < lastPoint) { QPointF p = ((QPointF *)points)[0] * state()->matrix; d->activeStroker->lineTo(p.x(), p.y()); points += 2; - ++types; } if (path.hasImplicitClose()) d->activeStroker->lineTo(p.x(), p.y()); diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 898a996..d17c711 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -72,6 +72,7 @@ #include <private/qmath_p.h> #include <qstatictext.h> #include <private/qstatictext_p.h> +#include <private/qstylehelper_p.h> QT_BEGIN_NAMESPACE @@ -970,7 +971,7 @@ void QPainterPrivate::updateState(QPainterState *newState) devices. If the painter is active, device() returns the paint device on which the painter paints, and paintEngine() returns the paint engine that the painter is currently operating on. For more - information, see \l {The Paint System} documentation. + information, see the \l {Paint System}. Sometimes it is desirable to make someone else paint on an unusual QPaintDevice. QPainter supports a static function to do this, @@ -1015,7 +1016,7 @@ void QPainterPrivate::updateState(QPainterState *newState) \o viewport(), window(), worldTransform() make up the painter's coordinate transformation system. For more information, see the \l - {Coordinate Transformations} section and the \l {The Coordinate + {Coordinate Transformations} section and the \l {Coordinate System} documentation. \o hasClipping() tells whether the painter clips at all. (The paint @@ -1222,7 +1223,7 @@ void QPainterPrivate::updateState(QPainterState *newState) All the tranformation operations operate on the transformation worldTransform(). A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see - the \l {The Coordinate System} and QTransform documentation. + the \l {Coordinate System} and QTransform documentation. The setWorldTransform() function can replace or add to the currently set worldTransform(). The resetTransform() function resets any @@ -1244,7 +1245,7 @@ void QPainterPrivate::updateState(QPainterState *newState) logical coordinates, and the worldTransform() is identical with the transformation matrix. - See also \l {The Coordinate System} documentation. + See also \l {Coordinate System} \section1 Clipping @@ -1563,7 +1564,6 @@ void QPainter::initFrom(const QWidget *widget) d->engine->setDirty(QPaintEngine::DirtyBrush); d->engine->setDirty(QPaintEngine::DirtyFont); } - d->state->layoutDirection = widget->layoutDirection(); } @@ -1873,7 +1873,7 @@ bool QPainter::begin(QPaintDevice *pd) QWidget *widget = static_cast<QWidget *>(d->original_device); initFrom(widget); } else { - d->state->layoutDirection = QApplication::layoutDirection(); + d->state->layoutDirection = Qt::LayoutDirectionAuto; // make sure we have a font compatible with the paintdevice d->state->deviceFont = d->state->font = QFont(d->state->deviceFont, device()); } @@ -2880,8 +2880,7 @@ void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op) functions is safe. For more information about the coordinate system, transformations - and window-viewport conversion, see \l {The Coordinate System} - documentation. + and window-viewport conversion, see \l {Coordinate System}. \sa setWorldTransform(), QTransform */ @@ -2901,7 +2900,7 @@ void QPainter::setWorldMatrix(const QMatrix &matrix, bool combine) preserve the properties of perspective transformations. \sa {QPainter#Coordinate Transformations}{Coordinate Transformations}, - {The Coordinate System} + {Coordinate System} */ const QMatrix &QPainter::worldMatrix() const @@ -3044,7 +3043,7 @@ void QPainter::setWorldMatrixEnabled(bool enable) Returns true if world transformation is enabled; otherwise returns false. - \sa setWorldMatrixEnabled(), worldTransform(), {The Coordinate System} + \sa setWorldMatrixEnabled(), worldTransform(), {Coordinate System} */ bool QPainter::worldMatrixEnabled() const @@ -3386,7 +3385,7 @@ void QPainter::drawPath(const QPainterPath &path) \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 6 \endtable - \sa drawLines(), drawPolyline(), {The Coordinate System} + \sa drawLines(), drawPolyline(), {Coordinate System} */ /*! @@ -3433,7 +3432,7 @@ void QPainter::drawPath(const QPainterPath &path) \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 7 \endtable - \sa drawRects(), drawPolygon(), {The Coordinate System} + \sa drawRects(), drawPolygon(), {Coordinate System} */ /*! @@ -3597,7 +3596,7 @@ void QPainter::drawRects(const QRect *rects, int rectCount) Draws a single point at the given \a position using the current pen's color. - \sa {The Coordinate System} + \sa {Coordinate System} */ /*! @@ -3619,7 +3618,7 @@ void QPainter::drawRects(const QRect *rects, int rectCount) Draws the first \a pointCount points in the array \a points using the current pen's color. - \sa {The Coordinate System} + \sa {Coordinate System} */ void QPainter::drawPoints(const QPointF *points, int pointCount) { @@ -4225,7 +4224,7 @@ void QPainter::drawRoundRect(const QRectF &r, int xRnd, int yRnd) \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 9 \endtable - \sa drawPie(), {The Coordinate System} + \sa drawPie(), {Coordinate System} */ void QPainter::drawEllipse(const QRectF &r) { @@ -4239,8 +4238,6 @@ void QPainter::drawEllipse(const QRectF &r) return; QRectF rect(r.normalized()); - if (rect.isEmpty()) - return; if (d->extended) { d->extended->drawEllipse(rect); @@ -4282,8 +4279,6 @@ void QPainter::drawEllipse(const QRect &r) return; QRect rect(r.normalized()); - if (rect.isEmpty()) - return; if (d->extended) { d->extended->drawEllipse(rect); @@ -4355,7 +4350,7 @@ void QPainter::drawEllipse(const QRect &r) \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 10 \endtable - \sa drawPie(), drawChord(), {The Coordinate System} + \sa drawPie(), drawChord(), {Coordinate System} */ void QPainter::drawArc(const QRectF &r, int a, int alen) @@ -4419,7 +4414,7 @@ void QPainter::drawArc(const QRectF &r, int a, int alen) \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 11 \endtable - \sa drawEllipse(), drawChord(), {The Coordinate System} + \sa drawEllipse(), drawChord(), {Coordinate System} */ void QPainter::drawPie(const QRectF &r, int a, int alen) { @@ -4488,7 +4483,7 @@ void QPainter::drawPie(const QRectF &r, int a, int alen) \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 12 \endtable - \sa drawArc(), drawPie(), {The Coordinate System} + \sa drawArc(), drawPie(), {Coordinate System} */ void QPainter::drawChord(const QRectF &r, int a, int alen) { @@ -4779,7 +4774,7 @@ void QPainter::drawLines(const QPoint *pointPairs, int lineCount) \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 13 \endtable - \sa drawLines(), drawPolygon(), {The Coordinate System} + \sa drawLines(), drawPolygon(), {Coordinate System} */ void QPainter::drawPolyline(const QPointF *points, int pointCount) { @@ -4918,7 +4913,7 @@ void QPainter::drawPolyline(const QPoint *points, int pointCount) \l{Qt::FillRule} for a more detailed description of these fill rules. - \sa drawConvexPolygon(), drawPolyline(), {The Coordinate System} + \sa drawConvexPolygon(), drawPolyline(), {Coordinate System} */ void QPainter::drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule) { @@ -5069,7 +5064,7 @@ void QPainter::drawPolygon(const QPoint *points, int pointCount, Qt::FillRule fi On some platforms (e.g. X11), the drawConvexPolygon() function can be faster than the drawPolygon() function. - \sa drawPolygon(), drawPolyline(), {The Coordinate System} + \sa drawPolygon(), drawPolyline(), {Coordinate System} */ /*! @@ -5856,14 +5851,24 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText return; } + if (d->extended->type() == QPaintEngine::OpenGL2 && !staticText_d->untransformedCoordinates) { + staticText_d->untransformedCoordinates = true; + staticText_d->needsRelayout = true; + } else if (d->extended->type() != QPaintEngine::OpenGL2 && staticText_d->untransformedCoordinates) { + staticText_d->untransformedCoordinates = false; + staticText_d->needsRelayout = true; + } + // Don't recalculate entire layout because of translation, rather add the dx and dy // into the position to move each text item the correct distance. - QPointF transformedPosition = topLeftPosition * d->state->matrix; - QTransform matrix = d->state->matrix; + QPointF transformedPosition = topLeftPosition; + if (!staticText_d->untransformedCoordinates) + transformedPosition = transformedPosition * d->state->matrix; + QTransform oldMatrix; // The translation has been applied to transformedPosition. Remove translation // component from matrix. - if (d->state->matrix.isTranslating()) { + if (d->state->matrix.isTranslating() && !staticText_d->untransformedCoordinates) { qreal m11 = d->state->matrix.m11(); qreal m12 = d->state->matrix.m12(); qreal m13 = d->state->matrix.m13(); @@ -5872,6 +5877,7 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText qreal m23 = d->state->matrix.m23(); qreal m33 = d->state->matrix.m33(); + oldMatrix = d->state->matrix; d->state->matrix.setMatrix(m11, m12, m13, m21, m22, m23, 0.0, 0.0, m33); @@ -5880,7 +5886,7 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText // If the transform is not identical to the text transform, // we have to relayout the text (for other transformations than plain translation) bool staticTextNeedsReinit = staticText_d->needsRelayout; - if (staticText_d->matrix != d->state->matrix) { + if (!staticText_d->untransformedCoordinates && staticText_d->matrix != d->state->matrix) { staticText_d->matrix = d->state->matrix; staticTextNeedsReinit = true; } @@ -5919,8 +5925,8 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText if (currentColor != oldPen.color()) setPen(oldPen); - if (matrix.isTranslating()) - d->state->matrix = matrix; + if (!staticText_d->untransformedCoordinates && oldMatrix.isTranslating()) + d->state->matrix = oldMatrix; } /*! @@ -5938,6 +5944,23 @@ void QPainter::drawText(const QPointF &p, const QString &str, int tf, int justif if (!d->engine || str.isEmpty() || pen().style() == Qt::NoPen) return; + if (tf & Qt::TextBypassShaping) { + // Skip harfbuzz complex shaping, shape using glyph advances only + int len = str.length(); + int numGlyphs = len; + QVarLengthGlyphLayoutArray glyphs(len); + QFontEngine *fontEngine = d->state->font.d->engineForScript(QUnicodeTables::Common); + if (!fontEngine->stringToCMap(str.data(), len, &glyphs, &numGlyphs, 0)) { + glyphs.resize(numGlyphs); + if (!fontEngine->stringToCMap(str.data(), len, &glyphs, &numGlyphs, 0)) + Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice"); + } + + QTextItemInt gf(glyphs, &d->state->font, fontEngine); + drawTextItem(p, gf); + return; + } + QStackTextEngine engine(str, d->state->font); engine.option.setTextDirection(d->state->layoutDirection); if (tf & (Qt::TextForceLeftToRight|Qt::TextForceRightToLeft)) { @@ -5977,12 +6000,17 @@ void QPainter::drawText(const QPointF &p, const QString &str, int tf, int justif gf.glyphs = engine.shapedGlyphs(&si); gf.chars = engine.layoutData->string.unicode() + si.position; gf.num_chars = engine.length(item); - gf.width = si.width; + if (engine.forceJustification) { + for (int j=0; j<gf.glyphs.numGlyphs; ++j) + gf.width += gf.glyphs.effectiveAdvance(j); + } else { + gf.width = si.width; + } gf.logClusters = engine.logClusters(&si); drawTextItem(QPointF(x.toReal(), p.y()), gf); - x += si.width; + x += gf.width; } } @@ -6213,10 +6241,9 @@ static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) { const qreal radiusBase = qMax(qreal(1), maxRadius); - QString key = QLatin1String("WaveUnderline-"); - key += pen.color().name(); - key += QLatin1Char('-'); - key += QString::number(radiusBase); + QString key = QLatin1Literal("WaveUnderline-") + % pen.color().name() + % HexString<qreal>(radiusBase); QPixmap pixmap; if (QPixmapCache::find(key, pixmap)) @@ -7107,7 +7134,7 @@ bool QPainter::viewTransformEnabled() const The default window rectangle is the same as the device's rectangle. - \sa window(), viewTransformEnabled(), {The Coordinate + \sa window(), viewTransformEnabled(), {Coordinate System#Window-Viewport Conversion}{Window-Viewport Conversion} */ @@ -7171,7 +7198,7 @@ QRect QPainter::window() const The default viewport rectangle is the same as the device's rectangle. - \sa viewport(), viewTransformEnabled() {The Coordinate + \sa viewport(), viewTransformEnabled() {Coordinate System#Window-Viewport Conversion}{Window-Viewport Conversion} */ @@ -7255,7 +7282,7 @@ QRect QPainter::viewport() const Enables view transformations if \a enable is true, or disables view transformations if \a enable is false. - \sa viewTransformEnabled(), {The Coordinate System#Window-Viewport + \sa viewTransformEnabled(), {Coordinate System#Window-Viewport Conversion}{Window-Viewport Conversion} */ @@ -8024,7 +8051,10 @@ start_lengthVariant: Sets the layout direction used by the painter when drawing text, to the specified \a direction. - \sa layoutDirection(), drawText(), {QPainter#Settings}{Settings} + The default is Qt::LayoutDirectionAuto, which will implicitly determine the + direction from the text drawn. + + \sa QTextOption::setTextDirection(), layoutDirection(), drawText(), {QPainter#Settings}{Settings} */ void QPainter::setLayoutDirection(Qt::LayoutDirection direction) { @@ -8036,12 +8066,12 @@ void QPainter::setLayoutDirection(Qt::LayoutDirection direction) /*! Returns the layout direction used by the painter when drawing text. - \sa setLayoutDirection(), drawText(), {QPainter#Settings}{Settings} + \sa QTextOption::textDirection(), setLayoutDirection(), drawText(), {QPainter#Settings}{Settings} */ Qt::LayoutDirection QPainter::layoutDirection() const { Q_D(const QPainter); - return d->state ? d->state->layoutDirection : Qt::LeftToRight; + return d->state ? d->state->layoutDirection : Qt::LayoutDirectionAuto; } QPainterState::QPainterState(const QPainterState *s) diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index f5a698e..ffd0d5c 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -2307,7 +2307,7 @@ QPainterPath &QPainterPath::operator-=(const QPainterPath &other) Writes the given painter \a path to the given \a stream, and returns a reference to the \a stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &s, const QPainterPath &p) { @@ -2334,7 +2334,7 @@ QDataStream &operator<<(QDataStream &s, const QPainterPath &p) Reads a painter path from the given \a stream into the specified \a path, and returns a reference to the \a stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &s, QPainterPath &p) { diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp index c910024..78553c9 100644 --- a/src/gui/painting/qpathclipper.cpp +++ b/src/gui/painting/qpathclipper.cpp @@ -278,7 +278,8 @@ private: }; SegmentTree::SegmentTree(QPathSegments &segments) - : m_segments(segments) + : m_segments(segments), + m_intersections(0) { m_bounds.x1 = qt_inf(); m_bounds.y1 = qt_inf(); @@ -806,7 +807,7 @@ void QWingedEdge::intersectAndAdd() for (int i = 0; i < m_segments.points(); ++i) addVertex(m_segments.pointAt(i)); - QDataBuffer<QPathSegments::Intersection> intersections; + QDataBuffer<QPathSegments::Intersection> intersections(m_segments.segments()); for (int i = 0; i < m_segments.segments(); ++i) { intersections.reset(); @@ -857,11 +858,17 @@ void QWingedEdge::intersectAndAdd() } } -QWingedEdge::QWingedEdge() +QWingedEdge::QWingedEdge() : + m_edges(0), + m_vertices(0), + m_segments(0) { } -QWingedEdge::QWingedEdge(const QPainterPath &subject, const QPainterPath &clip) +QWingedEdge::QWingedEdge(const QPainterPath &subject, const QPainterPath &clip) : + m_edges(subject.length()), + m_vertices(subject.length()), + m_segments(subject.length()) { m_segments.setPath(subject); m_segments.addPath(clip); @@ -1414,9 +1421,9 @@ bool QPathClipper::intersect() else if (clipIsRect) return subjectPath.intersects(r2); - QPathSegments a; + QPathSegments a(subjectPath.length()); a.setPath(subjectPath); - QPathSegments b; + QPathSegments b(clipPath.length()); b.setPath(clipPath); QIntersectionFinder finder; @@ -1459,9 +1466,9 @@ bool QPathClipper::contains() if (clipIsRect) return subjectPath.contains(r2); - QPathSegments a; + QPathSegments a(subjectPath.length()); a.setPath(subjectPath); - QPathSegments b; + QPathSegments b(clipPath.length()); b.setPath(clipPath); QIntersectionFinder finder; diff --git a/src/gui/painting/qpathclipper_p.h b/src/gui/painting/qpathclipper_p.h index 7962400..fab618d 100644 --- a/src/gui/painting/qpathclipper_p.h +++ b/src/gui/painting/qpathclipper_p.h @@ -199,7 +199,7 @@ public: }; - QPathSegments(); + QPathSegments(int reserve); void setPath(const QPainterPath &path); void addPath(const QPainterPath &path); @@ -345,7 +345,10 @@ inline QPathVertex::operator QPointF() const return QPointF(x, y); } -inline QPathSegments::QPathSegments() +inline QPathSegments::QPathSegments(int reserve) : + m_points(reserve), + m_segments(reserve), + m_intersections(reserve) { } diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 44049c0..6e02435 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -971,12 +971,17 @@ void QPdfBaseEngine::drawPoints (const QPointF *points, int pointCount) if (!points) return; + Q_D(QPdfBaseEngine); QPainterPath p; for (int i=0; i!=pointCount;++i) { p.moveTo(points[i]); p.lineTo(points[i] + QPointF(0, 0.001)); } + + bool hadBrush = d->hasBrush; + d->hasBrush = false; drawPath(p); + d->hasBrush = hadBrush; } void QPdfBaseEngine::drawLines (const QLineF *lines, int lineCount) @@ -984,12 +989,16 @@ void QPdfBaseEngine::drawLines (const QLineF *lines, int lineCount) if (!lines) return; + Q_D(QPdfBaseEngine); QPainterPath p; for (int i=0; i!=lineCount;++i) { p.moveTo(lines[i].p1()); p.lineTo(lines[i].p2()); } + bool hadBrush = d->hasBrush; + d->hasBrush = false; drawPath(p); + d->hasBrush = hadBrush; } void QPdfBaseEngine::drawRects (const QRectF *rects, int rectCount) diff --git a/src/gui/painting/qpen.cpp b/src/gui/painting/qpen.cpp index e290cbe..2e43984 100644 --- a/src/gui/painting/qpen.cpp +++ b/src/gui/painting/qpen.cpp @@ -92,7 +92,7 @@ typedef QPenPrivate QPenData; convenience functions to extract and set the color of the pen's brush, respectively. Pens may also be compared and streamed. - For more information about painting in general, see \l{The Paint + For more information about painting in general, see the \l{Paint System} documentation. \tableofcontents @@ -872,7 +872,7 @@ bool QPen::isDetached() Writes the given \a pen to the given \a stream and returns a reference to the \a stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &s, const QPen &p) @@ -918,7 +918,7 @@ QDataStream &operator<<(QDataStream &s, const QPen &p) Reads a pen from the given \a stream into the given \a pen and returns a reference to the \a stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &s, QPen &p) diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp index b68314f..2fb52b5 100644 --- a/src/gui/painting/qpolygon.cpp +++ b/src/gui/painting/qpolygon.cpp @@ -719,7 +719,7 @@ QPolygon::operator QVariant() const Writes the given \a polygon to the given \a stream, and returns a reference to the stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &s, const QPolygon &a) { @@ -735,7 +735,7 @@ QDataStream &operator<<(QDataStream &s, const QPolygon &a) Reads a polygon from the given \a stream into the given \a polygon, and returns a reference to the stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &s, QPolygon &a) { @@ -755,7 +755,7 @@ QDataStream &operator>>(QDataStream &s, QPolygon &a) Writes the given \a polygon to the given \a stream, and returns a reference to the stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator<<(QDataStream &s, const QPolygonF &a) @@ -776,7 +776,7 @@ QDataStream &operator<<(QDataStream &s, const QPolygonF &a) Reads a polygon from the given \a stream into the given \a polygon, and returns a reference to the stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream &operator>>(QDataStream &s, QPolygonF &a) diff --git a/src/gui/painting/qpolygonclipper_p.h b/src/gui/painting/qpolygonclipper_p.h index 1b4cbb3..cdaac1c 100644 --- a/src/gui/painting/qpolygonclipper_p.h +++ b/src/gui/painting/qpolygonclipper_p.h @@ -62,7 +62,8 @@ QT_BEGIN_NAMESPACE template <typename InType, typename OutType, typename CastType> class QPolygonClipper { public: - QPolygonClipper() + QPolygonClipper() : + buffer1(0), buffer2(0) { x1 = y1 = x2 = y2 = 0; } diff --git a/src/gui/painting/qprintengine_pdf.cpp b/src/gui/painting/qprintengine_pdf.cpp index b8bf15e..2955e39 100644 --- a/src/gui/painting/qprintengine_pdf.cpp +++ b/src/gui/painting/qprintengine_pdf.cpp @@ -931,29 +931,16 @@ void QPdfEnginePrivate::writeHeader() void QPdfEnginePrivate::writeInfo() { info = addXrefEntry(-1); - - // The 'text string' type in PDF is encoded either as PDFDocEncoding, or - // Unicode UTF-16 with a Unicode byte order mark as the first character - // (0xfeff), with the high-order byte first. - QByteArray array("<<\n/Title (\xfe\xff"); - const ushort *utf16Title = title.utf16(); - for (int i=0; i < title.size(); ++i) { - array.append((*(utf16Title + i)) >> 8); - array.append((*(utf16Title + i)) & 0xff); - } - array.append(")\n/Creator (\xfe\xff"); - const ushort *utf16Creator = creator.utf16(); - for (int i=0; i < creator.size(); ++i) { - array.append((*(utf16Creator + i)) >> 8); - array.append((*(utf16Creator + i)) & 0xff); - } - array.append(")\n/Producer (Qt " QT_VERSION_STR " (C) 2010 Nokia Corporation and/or its subsidiary(-ies))\n"); - write(array); - + xprintf("<<\n/Title "); + printString(title); + xprintf("\n/Creator "); + printString(creator); + xprintf("\n/Producer "); + printString(QString::fromLatin1("Qt " QT_VERSION_STR " (C) 2010 Nokia Corporation and/or its subsidiary(-ies)")); QDateTime now = QDateTime::currentDateTime().toUTC(); QTime t = now.time(); QDate d = now.date(); - xprintf("/CreationDate (D:%d%02d%02d%02d%02d%02d)\n", + xprintf("\n/CreationDate (D:%d%02d%02d%02d%02d%02d)\n", d.year(), d.month(), d.day(), @@ -1230,6 +1217,25 @@ int QPdfEnginePrivate::addXrefEntry(int object, bool printostr) return object; } +void QPdfEnginePrivate::printString(const QString &string) { + // The 'text string' type in PDF is encoded either as PDFDocEncoding, or + // Unicode UTF-16 with a Unicode byte order mark as the first character + // (0xfeff), with the high-order byte first. + QByteArray array("(\xfe\xff"); + const ushort *utf16 = string.utf16(); + + for (int i=0; i < string.size(); ++i) { + char part[2] = {char((*(utf16 + i)) >> 8), char((*(utf16 + i)) & 0xff)}; + for(int j=0; j < 2; ++j) { + if (part[j] == '(' || part[j] == ')' || part[j] == '\\') + array.append('\\'); + array.append(part[j]); + } + } + array.append(")"); + write(array); +} + QT_END_NAMESPACE #endif // QT_NO_PRINTER diff --git a/src/gui/painting/qprintengine_pdf_p.h b/src/gui/painting/qprintengine_pdf_p.h index cb6c59d..e0ca56f 100644 --- a/src/gui/painting/qprintengine_pdf_p.h +++ b/src/gui/painting/qprintengine_pdf_p.h @@ -170,6 +170,7 @@ private: void writePage(); int addXrefEntry(int object, bool printostr = true); + void printString(const QString &string); void xprintf(const char* fmt, ...); inline void write(const QByteArray &data) { stream->writeRawData(data.constData(), data.size()); diff --git a/src/gui/painting/qrasterdefs_p.h b/src/gui/painting/qrasterdefs_p.h index c33fa57..19a0b16 100644 --- a/src/gui/painting/qrasterdefs_p.h +++ b/src/gui/painting/qrasterdefs_p.h @@ -81,7 +81,6 @@ QT_FT_BEGIN_HEADER - /*************************************************************************/ /* */ /* <Section> */ @@ -837,7 +836,7 @@ QT_FT_BEGIN_HEADER /* A handle (pointer) to a raster object. Each object can be used */ /* independently to convert an outline into a bitmap or pixmap. */ /* */ - typedef struct QT_FT_RasterRec_* QT_FT_Raster; + typedef struct TRaster_ *QT_FT_Raster; /*************************************************************************/ @@ -1118,8 +1117,7 @@ QT_FT_BEGIN_HEADER /* ignored by a given raster implementation. */ /* */ typedef int - (*QT_FT_Raster_NewFunc)( void* memory, - QT_FT_Raster* raster ); + (*QT_FT_Raster_NewFunc)( QT_FT_Raster* raster ); #define QT_FT_Raster_New_Func QT_FT_Raster_NewFunc diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp index 51d01c9..f8f8afb 100644 --- a/src/gui/painting/qrasterizer.cpp +++ b/src/gui/painting/qrasterizer.cpp @@ -198,9 +198,11 @@ public: }; QScanConverter::QScanConverter() - : m_alloc(0) + : m_lines(0) + , m_alloc(0) , m_size(0) , m_intersections(0) + , m_active(0) { } @@ -310,6 +312,10 @@ struct QBoolToType template <typename T> void qScanConvert(QScanConverter &d, T allVertical) { + if (!d.m_lines.size()) { + d.m_active.reset(); + return; + } qSort(d.m_lines.data(), d.m_lines.data() + d.m_lines.size(), QT_PREPEND_NAMESPACE(topOrder)); int line = 0; for (int y = d.m_lines.first().top; y <= d.m_bottom; ++y) { diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp index e43544c..eabbd8a 100644 --- a/src/gui/painting/qstroker.cpp +++ b/src/gui/painting/qstroker.cpp @@ -120,8 +120,8 @@ private: class QSubpathFlatIterator { public: - QSubpathFlatIterator(const QDataBuffer<QStrokerOps::Element> *path) - : m_path(path), m_pos(0), m_curve_index(-1) { } + QSubpathFlatIterator(const QDataBuffer<QStrokerOps::Element> *path, qreal threshold) + : m_path(path), m_pos(0), m_curve_index(-1), m_curve_threshold(threshold) { } inline bool hasNext() const { return m_curve_index >= 0 || m_pos < m_path->size(); } @@ -152,7 +152,7 @@ public: QPointF(qt_fixed_to_real(m_path->at(m_pos+1).x), qt_fixed_to_real(m_path->at(m_pos+1).y)), QPointF(qt_fixed_to_real(m_path->at(m_pos+2).x), - qt_fixed_to_real(m_path->at(m_pos+2).y))).toPolygon(); + qt_fixed_to_real(m_path->at(m_pos+2).y))).toPolygon(m_curve_threshold); m_curve_index = 1; e.type = QPainterPath::LineToElement; e.x = m_curve.at(0).x(); @@ -169,6 +169,7 @@ private: int m_pos; QPolygonF m_curve; int m_curve_index; + qreal m_curve_threshold; }; template <class Iterator> bool qt_stroke_side(Iterator *it, QStroker *stroker, @@ -187,7 +188,12 @@ static inline qreal adapted_angle_on_x(const QLineF &line) } QStrokerOps::QStrokerOps() - : m_customData(0), m_moveTo(0), m_lineTo(0), m_cubicTo(0) + : m_elements(0) + , m_curveThreshold(qt_real_to_fixed(0.25)) + , m_customData(0) + , m_moveTo(0) + , m_lineTo(0) + , m_cubicTo(0) { } @@ -195,7 +201,6 @@ QStrokerOps::~QStrokerOps() { } - /*! Prepares the stroker. Call this function once before starting a stroke by calling moveTo, lineTo or cubicTo. @@ -238,6 +243,7 @@ void QStrokerOps::strokePath(const QPainterPath &path, void *customData, const Q if (path.isEmpty()) return; + setCurveThresholdFromTransform(matrix); begin(customData); int count = path.elementCount(); if (matrix.isIdentity()) { @@ -308,6 +314,8 @@ void QStrokerOps::strokePolygon(const QPointF *points, int pointCount, bool impl { if (!pointCount) return; + + setCurveThresholdFromTransform(matrix); begin(data); if (matrix.isIdentity()) { moveTo(qt_real_to_fixed(points[0].x()), qt_real_to_fixed(points[0].y())); @@ -348,6 +356,7 @@ void QStrokerOps::strokeEllipse(const QRectF &rect, void *data, const QTransform } } + setCurveThresholdFromTransform(matrix); begin(data); moveTo(qt_real_to_fixed(start.x()), qt_real_to_fixed(start.y())); for (int i=0; i<12; i+=3) { @@ -366,12 +375,10 @@ QStroker::QStroker() { m_strokeWidth = qt_real_to_fixed(1); m_miterLimit = qt_real_to_fixed(2); - m_curveThreshold = qt_real_to_fixed(0.25); } QStroker::~QStroker() { - } Qt::PenCapStyle QStroker::capForJoinMode(LineJoinMode mode) @@ -1135,7 +1142,7 @@ void QDashStroker::processCurrentSubpath() QPainterPath dashPath; - QSubpathFlatIterator it(&m_elements); + QSubpathFlatIterator it(&m_elements, m_curveThreshold); qfixed2d prev = it.next(); bool clipping = !m_clip_rect.isEmpty(); diff --git a/src/gui/painting/qstroker_p.h b/src/gui/painting/qstroker_p.h index 3e622a8..d646135 100644 --- a/src/gui/painting/qstroker_p.h +++ b/src/gui/painting/qstroker_p.h @@ -124,6 +124,9 @@ typedef void (*qStrokerCubicToHook)(qfixed c1x, qfixed c1y, qfixed ex, qfixed ey, void *data); +// qtransform.cpp +Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); + class Q_GUI_EXPORT QStrokerOps { public: @@ -161,6 +164,16 @@ public: QRectF clipRect() const { return m_clip_rect; } void setClipRect(const QRectF &clip) { m_clip_rect = clip; } + void setCurveThresholdFromTransform(const QTransform &transform) + { + qreal scale; + qt_scaleForTransform(transform, &scale); + setCurveThreshold(scale == 0 ? qreal(0.5) : (qreal(0.5) / scale)); + } + + void setCurveThreshold(qfixed threshold) { m_curveThreshold = threshold; } + qfixed curveThreshold() const { return m_curveThreshold; } + protected: inline void emitMoveTo(qfixed x, qfixed y); inline void emitLineTo(qfixed x, qfixed y); @@ -170,6 +183,7 @@ protected: QDataBuffer<Element> m_elements; QRectF m_clip_rect; + qfixed m_curveThreshold; void *m_customData; qStrokerMoveToHook m_moveTo; @@ -208,9 +222,6 @@ public: void setMiterLimit(qfixed length) { m_miterLimit = length; } qfixed miterLimit() const { return m_miterLimit; } - void setCurveThreshold(qfixed threshold) { m_curveThreshold = threshold; } - qfixed curveThreshold() const { return m_curveThreshold; } - void joinPoints(qfixed x, qfixed y, const QLineF &nextLine, LineJoinMode join); inline void emitMoveTo(qfixed x, qfixed y); inline void emitLineTo(qfixed x, qfixed y); @@ -227,7 +238,6 @@ protected: qfixed m_strokeWidth; qfixed m_miterLimit; - qfixed m_curveThreshold; LineJoinMode m_capStyle; LineJoinMode m_joinStyle; diff --git a/src/gui/painting/qtextureglyphcache_p.h b/src/gui/painting/qtextureglyphcache_p.h index 390fe51..a818978 100644 --- a/src/gui/painting/qtextureglyphcache_p.h +++ b/src/gui/painting/qtextureglyphcache_p.h @@ -125,7 +125,7 @@ protected: }; -class QImageTextureGlyphCache : public QTextureGlyphCache +class Q_GUI_EXPORT QImageTextureGlyphCache : public QTextureGlyphCache { public: QImageTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix) diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 80b7520..47b7758 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -148,8 +148,8 @@ QT_BEGIN_NAMESPACE coordinate system. The standard coordinate system of a QPaintDevice has its origin located at the top-left position. The \e x values increase to the right; \e y values increase - downward. For a complete description, see the \l {The Coordinate - System}{coordinate system} documentation. + downward. For a complete description, see the \l {Coordinate + System} {coordinate system} documentation. QPainter has functions to translate, scale, shear and rotate the coordinate system without using a QTransform. For example: @@ -223,7 +223,7 @@ QT_BEGIN_NAMESPACE \snippet doc/src/snippets/transform/main.cpp 2 \endtable - \sa QPainter, {The Coordinate System}, {demos/affine}{Affine + \sa QPainter, {Coordinate System}, {demos/affine}{Affine Transformations Demo}, {Transformations Example} */ @@ -1028,7 +1028,7 @@ void QTransform::reset() Writes the given \a matrix to the given \a stream and returns a reference to the stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream & operator<<(QDataStream &s, const QTransform &m) { @@ -1052,7 +1052,7 @@ QDataStream & operator<<(QDataStream &s, const QTransform &m) Reads the given \a matrix from the given \a stream and returns a reference to the stream. - \sa {Format of the QDataStream Operators} + \sa {Serializing Qt Data Types} */ QDataStream & operator>>(QDataStream &s, QTransform &t) { @@ -1545,12 +1545,19 @@ static inline bool lineTo_clipped(QPainterPath &path, const QTransform &transfor return true; } +Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); static inline bool cubicTo_clipped(QPainterPath &path, const QTransform &transform, const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d, bool needsMoveTo) { // Convert projective xformed curves to line // segments so they can be transformed more accurately - QPolygonF segment = QBezier::fromPoints(a, b, c, d).toPolygon(); + + qreal scale; + qt_scaleForTransform(transform, &scale); + + qreal curveThreshold = scale == 0 ? qreal(0.25) : (qreal(0.25) / scale); + + QPolygonF segment = QBezier::fromPoints(a, b, c, d).toPolygon(curveThreshold); for (int i = 0; i < segment.size() - 1; ++i) if (lineTo_clipped(path, transform, segment.at(i), segment.at(i+1), needsMoveTo)) @@ -1619,7 +1626,7 @@ static QPainterPath mapProjective(const QTransform &transform, const QPainterPat QPainterPath QTransform::map(const QPainterPath &path) const { TransformationType t = inline_type(); - if (t == TxNone || path.isEmpty()) + if (t == TxNone || path.elementCount() == 0) return path; if (t >= TxProject) diff --git a/src/gui/painting/qwindowsurface.cpp b/src/gui/painting/qwindowsurface.cpp index 3b542bc..c42ead0 100644 --- a/src/gui/painting/qwindowsurface.cpp +++ b/src/gui/painting/qwindowsurface.cpp @@ -43,6 +43,7 @@ #include <qwidget.h> #include <private/qwidget_p.h> #include <private/qbackingstore_p.h> +#include <private/qapplication_p.h> QT_BEGIN_NAMESPACE @@ -120,8 +121,10 @@ public: QWindowSurface::QWindowSurface(QWidget *window) : d_ptr(new QWindowSurfacePrivate(window)) { - if (window) - window->setWindowSurface(this); + if (!QApplicationPrivate::runtime_graphics_system) { + if(window) + window->setWindowSurface(this); + } } /*! diff --git a/src/gui/painting/qwindowsurface_s60.cpp b/src/gui/painting/qwindowsurface_s60.cpp index b25dce5..477bd93 100644 --- a/src/gui/painting/qwindowsurface_s60.cpp +++ b/src/gui/painting/qwindowsurface_s60.cpp @@ -43,10 +43,15 @@ #include <QtGui/qpaintdevice.h> #include <private/qwidget_p.h> -#include "qwindowsurface_s60_p.h" +#include <private/qwindowsurface_s60_p.h> #include <private/qpixmap_s60_p.h> #include <private/qt_s60_p.h> -#include "private/qdrawhelper_p.h" +#include <private/qapplication_p.h> +#include <private/qdrawhelper_p.h> + +#ifdef QT_GRAPHICSSYSTEM_RUNTIME +#include <private/qgraphicssystem_runtime_p.h> +#endif QT_BEGIN_NAMESPACE @@ -79,13 +84,35 @@ QS60WindowSurface::QS60WindowSurface(QWidget* widget) setStaticContentsSupport(true); } + QS60WindowSurface::~QS60WindowSurface() { +#if defined(QT_GRAPHICSSYSTEM_RUNTIME) && defined(Q_SYMBIAN_SUPPORTS_SURFACES) + if(QApplicationPrivate::runtime_graphics_system) { + QRuntimeGraphicsSystem *runtimeGraphicsSystem = + static_cast<QRuntimeGraphicsSystem*>(QApplicationPrivate::graphics_system); + if(runtimeGraphicsSystem->graphicsSystemName() == QLatin1String("openvg")) { + + // Graphics system has been switched from raster to openvg. + // Issue empty redraw to clear the UI surface + + QWidget *w = window(); + RWindow *const window = static_cast<RWindow *>(w->winId()->DrawableWindow()); + window->BeginRedraw(); + window->EndRedraw(); + } + } +#endif + delete d_ptr; } void QS60WindowSurface::beginPaint(const QRegion &rgn) { +#ifdef Q_SYMBIAN_SUPPORTS_SURFACES + S60->wsSession().Finish(); +#endif + if (!qt_widget_private(window())->isOpaque) { QS60PixmapData *pixmapData = static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data()); pixmapData->beginDataAccess(); |