src/gui/painting/qpaintengine_raster.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 22 79de32ba3296
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
    98 #if defined(Q_WS_WIN64)
    98 #if defined(Q_WS_WIN64)
    99 #  include <malloc.h>
    99 #  include <malloc.h>
   100 #endif
   100 #endif
   101 #include <limits.h>
   101 #include <limits.h>
   102 
   102 
   103 #if defined(QT_NO_FPU) || (_MSC_VER >= 1300 && _MSC_VER < 1400)
       
   104 #  define FLOATING_POINT_BUGGY_OR_NO_FPU
       
   105 #endif
       
   106 
       
   107 QT_BEGIN_NAMESPACE
   103 QT_BEGIN_NAMESPACE
   108 
   104 
   109 extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp
   105 extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp
   110 
   106 
   111 #define qreal_to_fixed_26_6(f) (int(f * 64))
   107 #define qreal_to_fixed_26_6(f) (int(f * 64))
   473     d->systemStateChanged();
   469     d->systemStateChanged();
   474 
   470 
   475     QRasterPaintEngineState *s = state();
   471     QRasterPaintEngineState *s = state();
   476     ensureOutlineMapper();
   472     ensureOutlineMapper();
   477     d->outlineMapper->m_clip_rect = d->deviceRect.adjusted(-10, -10, 10, 10);
   473     d->outlineMapper->m_clip_rect = d->deviceRect.adjusted(-10, -10, 10, 10);
       
   474 
       
   475     // This is the upp
   478     QRect bounds(-QT_RASTER_COORD_LIMIT, -QT_RASTER_COORD_LIMIT,
   476     QRect bounds(-QT_RASTER_COORD_LIMIT, -QT_RASTER_COORD_LIMIT,
   479                  2*QT_RASTER_COORD_LIMIT, 2*QT_RASTER_COORD_LIMIT);
   477                  QT_RASTER_COORD_LIMIT*2 - 1, QT_RASTER_COORD_LIMIT * 2 - 1);
   480     d->outlineMapper->m_clip_rect = bounds.intersected(d->outlineMapper->m_clip_rect);
   478     d->outlineMapper->m_clip_rect = bounds.intersected(d->outlineMapper->m_clip_rect);
   481 
   479 
   482 
   480 
   483     d->rasterizer->setClipRect(d->deviceRect);
   481     d->rasterizer->setClipRect(d->deviceRect);
   484 
   482 
  3077 
  3075 
  3078     QVarLengthArray<QFixedPoint> positions;
  3076     QVarLengthArray<QFixedPoint> positions;
  3079     QVarLengthArray<glyph_t> glyphs;
  3077     QVarLengthArray<glyph_t> glyphs;
  3080     QTransform matrix = s->matrix;
  3078     QTransform matrix = s->matrix;
  3081     matrix.translate(p.x(), p.y());
  3079     matrix.translate(p.x(), p.y());
       
  3080     if (matrix.type() == QTransform::TxScale)
       
  3081         fe->setFontScale(matrix.m11());
  3082     ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
  3082     ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
  3083 
  3083 
  3084     const QFixed aliasDelta = QFixed::fromReal(aliasedCoordinateDelta);
  3084     const QFixed aliasDelta = QFixed::fromReal(aliasedCoordinateDelta);
  3085 
  3085 
  3086     for (int i=0; i<glyphs.size(); ++i) {
  3086     for (int i=0; i<glyphs.size(); ++i) {
  3092         const int x = qFloor(positions[i].x + metrics.x + aliasDelta);
  3092         const int x = qFloor(positions[i].x + metrics.x + aliasDelta);
  3093         const int y = qFloor(positions[i].y + metrics.y + aliasDelta);
  3093         const int y = qFloor(positions[i].y + metrics.y + aliasDelta);
  3094 
  3094 
  3095         alphaPenBlt(glyphBitmapBytes, glyphBitmapSize.iWidth, 8, x, y, glyphBitmapSize.iWidth, glyphBitmapSize.iHeight);
  3095         alphaPenBlt(glyphBitmapBytes, glyphBitmapSize.iWidth, 8, x, y, glyphBitmapSize.iWidth, glyphBitmapSize.iHeight);
  3096     }
  3096     }
       
  3097 
       
  3098     if (matrix.type() == QTransform::TxScale)
       
  3099         fe->setFontScale(1.0);
  3097 
  3100 
  3098     return;
  3101     return;
  3099 }
  3102 }
  3100 #endif // Q_OS_SYMBIAN && QT_NO_FREETYPE
  3103 #endif // Q_OS_SYMBIAN && QT_NO_FREETYPE
  3101 
  3104 
  3265         drawCachedGlyphs(p, ti);
  3268         drawCachedGlyphs(p, ti);
  3266         return;
  3269         return;
  3267     }
  3270     }
  3268 
  3271 
  3269 #elif defined (Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) // Q_WS_WIN || Q_WS_MAC
  3272 #elif defined (Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) // Q_WS_WIN || Q_WS_MAC
  3270     if (s->matrix.type() <= QTransform::TxTranslate) {
  3273     if (s->matrix.type() <= QTransform::TxTranslate
       
  3274         || (s->matrix.type() == QTransform::TxScale
       
  3275                 && (qFuzzyCompare(s->matrix.m11(), s->matrix.m22())))) {
  3271         drawGlyphsS60(p, ti);
  3276         drawGlyphsS60(p, ti);
  3272         return;
  3277         return;
  3273     }
  3278     }
  3274 #else // Q_WS_WIN || Q_WS_MAC
  3279 #else // Q_WS_WIN || Q_WS_MAC
  3275 
  3280 
  3668 
  3673 
  3669     ensurePen();
  3674     ensurePen();
  3670     if (((qpen_style(s->lastPen) == Qt::SolidLine && s->flags.fast_pen)
  3675     if (((qpen_style(s->lastPen) == Qt::SolidLine && s->flags.fast_pen)
  3671          || (qpen_style(s->lastPen) == Qt::NoPen && !s->flags.antialiased))
  3676          || (qpen_style(s->lastPen) == Qt::NoPen && !s->flags.antialiased))
  3672         && qMax(rect.width(), rect.height()) < QT_RASTER_COORD_LIMIT
  3677         && qMax(rect.width(), rect.height()) < QT_RASTER_COORD_LIMIT
  3673 #ifdef FLOATING_POINT_BUGGY_OR_NO_FPU
       
  3674         && qMax(rect.width(), rect.height()) < 128 // integer math breakdown
       
  3675 #endif
       
  3676         && s->matrix.type() <= QTransform::TxScale) // no shear
  3678         && s->matrix.type() <= QTransform::TxScale) // no shear
  3677     {
  3679     {
  3678         ensureBrush();
  3680         ensureBrush();
  3679         const QRectF r = s->matrix.mapRect(rect);
  3681         const QRectF r = s->matrix.mapRect(rect);
  3680         ProcessSpans penBlend = d->getPenFunc(r, &s->penData);
  3682         ProcessSpans penBlend = d->getPenFunc(r, &s->penData);
  6043 */
  6045 */
  6044 static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip,
  6046 static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip,
  6045                                    ProcessSpans pen_func, ProcessSpans brush_func,
  6047                                    ProcessSpans pen_func, ProcessSpans brush_func,
  6046                                    QSpanData *pen_data, QSpanData *brush_data)
  6048                                    QSpanData *pen_data, QSpanData *brush_data)
  6047 {
  6049 {
  6048 #ifdef FLOATING_POINT_BUGGY_OR_NO_FPU // no fpu, so use fixed point
       
  6049     const QFixed a = QFixed(rect.width()) >> 1;
       
  6050     const QFixed b = QFixed(rect.height()) >> 1;
       
  6051     QFixed d = b*b - (a*a*b) + ((a*a) >> 2);
       
  6052 #else
       
  6053     const qreal a = qreal(rect.width()) / 2;
  6050     const qreal a = qreal(rect.width()) / 2;
  6054     const qreal b = qreal(rect.height()) / 2;
  6051     const qreal b = qreal(rect.height()) / 2;
  6055     qreal d = b*b - (a*a*b) + 0.25*a*a;
  6052     qreal d = b*b - (a*a*b) + 0.25*a*a;
  6056 #endif
       
  6057 
  6053 
  6058     int x = 0;
  6054     int x = 0;
  6059     int y = (rect.height() + 1) / 2;
  6055     int y = (rect.height() + 1) / 2;
  6060     int startx = x;
  6056     int startx = x;
  6061 
  6057 
  6074     }
  6070     }
  6075     drawEllipsePoints(startx, y, x - startx + 1, rect, clip,
  6071     drawEllipsePoints(startx, y, x - startx + 1, rect, clip,
  6076                       pen_func, brush_func, pen_data, brush_data);
  6072                       pen_func, brush_func, pen_data, brush_data);
  6077 
  6073 
  6078     // region 2
  6074     // region 2
  6079 #ifdef FLOATING_POINT_BUGGY_OR_NO_FPU
       
  6080     d = b*b*(x + (QFixed(1) >> 1))*(x + (QFixed(1) >> 1))
       
  6081         + a*a*((y - 1)*(y - 1) - b*b);
       
  6082 #else
       
  6083     d = b*b*(x + 0.5)*(x + 0.5) + a*a*((y - 1)*(y - 1) - b*b);
  6075     d = b*b*(x + 0.5)*(x + 0.5) + a*a*((y - 1)*(y - 1) - b*b);
  6084 #endif
       
  6085     const int miny = rect.height() & 0x1;
  6076     const int miny = rect.height() & 0x1;
  6086     while (y > miny) {
  6077     while (y > miny) {
  6087         if (d < 0) { // select SE
  6078         if (d < 0) { // select SE
  6088             d += b*b*(2*x + 2) + a*a*(-2*y + 3);
  6079             d += b*b*(2*x + 2) + a*a*(-2*y + 3);
  6089             ++x;
  6080             ++x;