src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp	Tue Jul 06 15:10:48 2010 +0300
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp	Wed Aug 18 10:37:55 2010 +0300
@@ -1128,7 +1128,7 @@
     d->fill(path);
 }
 
-extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp
+extern Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp
 
 
 void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen)
@@ -1333,8 +1333,16 @@
     QFontEngineGlyphCache::Type glyphType = textItem->fontEngine->glyphFormat >= 0
                                             ? QFontEngineGlyphCache::Type(textItem->fontEngine->glyphFormat)
                                             : d->glyphCacheType;
+    if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
+        if (d->device->alphaRequested() || state()->matrix.type() > QTransform::TxTranslate
+            || (state()->composition_mode != QPainter::CompositionMode_Source
+            && state()->composition_mode != QPainter::CompositionMode_SourceOver))
+        {
+            glyphType = QFontEngineGlyphCache::Raster_A8;
+        }
+    }
 
-    d->drawCachedGlyphs(glyphType, textItem, true);
+    d->drawCachedGlyphs(glyphType, textItem);
 }
 
 bool QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src)
@@ -1401,14 +1409,14 @@
 
         {
             QStaticTextItem staticTextItem;
-            staticTextItem.chars = ti.chars;
+            staticTextItem.chars = const_cast<QChar *>(ti.chars);
             staticTextItem.fontEngine = ti.fontEngine;
             staticTextItem.glyphs = glyphs.data();
             staticTextItem.numChars = ti.num_chars;
             staticTextItem.numGlyphs = glyphs.size();
             staticTextItem.glyphPositions = positions.data();
 
-            d->drawCachedGlyphs(glyphType, &staticTextItem, false);
+            d->drawCachedGlyphs(glyphType, &staticTextItem);
         }
         return;
     }
@@ -1439,21 +1447,16 @@
 // #define QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO
 
 void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType,
-                                                QStaticTextItem *staticTextItem,
-                                                bool includeMatrixInCache)
+                                                QStaticTextItem *staticTextItem)
 {
     Q_Q(QGL2PaintEngineEx);
 
     QOpenGL2PaintEngineState *s = q->state();
 
     QGLTextureGlyphCache *cache =
-        (QGLTextureGlyphCache *) staticTextItem->fontEngine->glyphCache(ctx, glyphType,
-                                                                        includeMatrixInCache
-                                                                          ? s->matrix
-                                                                          : QTransform());
+        (QGLTextureGlyphCache *) staticTextItem->fontEngine->glyphCache(ctx, glyphType, QTransform());
     if (!cache || cache->cacheType() != glyphType) {
-        cache = new QGLTextureGlyphCache(ctx, glyphType,
-                                         includeMatrixInCache ? s->matrix : QTransform());
+        cache = new QGLTextureGlyphCache(ctx, glyphType, QTransform());
         staticTextItem->fontEngine->setGlyphCache(ctx, cache);
     }
 
@@ -1561,13 +1564,6 @@
     QBrush pensBrush = q->state()->pen.brush();
     setBrush(pensBrush);
 
-    // When painting a QStaticTextItem, the glyph positions are already in device coordinates,
-    // therefore we temporarily set an identity matrix on the painter for the draw call to
-    // avoid transforming the positions twice.
-    QTransform old = s->matrix;
-    if (includeMatrixInCache)
-        s->matrix = QTransform();
-
     if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
 
         // Subpixel antialiasing without gamma correction
@@ -1664,9 +1660,6 @@
 #else
     glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data());
 #endif
-
-    if (includeMatrixInCache)
-        s->matrix = old;
 }
 
 void QGL2PaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,