1331 ensureActive(); |
1331 ensureActive(); |
1332 |
1332 |
1333 QFontEngineGlyphCache::Type glyphType = textItem->fontEngine->glyphFormat >= 0 |
1333 QFontEngineGlyphCache::Type glyphType = textItem->fontEngine->glyphFormat >= 0 |
1334 ? QFontEngineGlyphCache::Type(textItem->fontEngine->glyphFormat) |
1334 ? QFontEngineGlyphCache::Type(textItem->fontEngine->glyphFormat) |
1335 : d->glyphCacheType; |
1335 : d->glyphCacheType; |
1336 |
1336 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { |
1337 d->drawCachedGlyphs(glyphType, textItem, true); |
1337 if (d->device->alphaRequested() || state()->matrix.type() > QTransform::TxTranslate |
|
1338 || (state()->composition_mode != QPainter::CompositionMode_Source |
|
1339 && state()->composition_mode != QPainter::CompositionMode_SourceOver)) |
|
1340 { |
|
1341 glyphType = QFontEngineGlyphCache::Raster_A8; |
|
1342 } |
|
1343 } |
|
1344 |
|
1345 d->drawCachedGlyphs(glyphType, textItem); |
1338 } |
1346 } |
1339 |
1347 |
1340 bool QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src) |
1348 bool QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src) |
1341 { |
1349 { |
1342 Q_D(QGL2PaintEngineEx); |
1350 Q_D(QGL2PaintEngineEx); |
1399 QTransform matrix = QTransform::fromTranslate(p.x(), p.y()); |
1407 QTransform matrix = QTransform::fromTranslate(p.x(), p.y()); |
1400 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
1408 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); |
1401 |
1409 |
1402 { |
1410 { |
1403 QStaticTextItem staticTextItem; |
1411 QStaticTextItem staticTextItem; |
1404 staticTextItem.chars = ti.chars; |
1412 staticTextItem.chars = const_cast<QChar *>(ti.chars); |
1405 staticTextItem.fontEngine = ti.fontEngine; |
1413 staticTextItem.fontEngine = ti.fontEngine; |
1406 staticTextItem.glyphs = glyphs.data(); |
1414 staticTextItem.glyphs = glyphs.data(); |
1407 staticTextItem.numChars = ti.num_chars; |
1415 staticTextItem.numChars = ti.num_chars; |
1408 staticTextItem.numGlyphs = glyphs.size(); |
1416 staticTextItem.numGlyphs = glyphs.size(); |
1409 staticTextItem.glyphPositions = positions.data(); |
1417 staticTextItem.glyphPositions = positions.data(); |
1410 |
1418 |
1411 d->drawCachedGlyphs(glyphType, &staticTextItem, false); |
1419 d->drawCachedGlyphs(glyphType, &staticTextItem); |
1412 } |
1420 } |
1413 return; |
1421 return; |
1414 } |
1422 } |
1415 |
1423 |
1416 QPaintEngineEx::drawTextItem(p, ti); |
1424 QPaintEngineEx::drawTextItem(p, ti); |
1437 } |
1445 } |
1438 |
1446 |
1439 // #define QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO |
1447 // #define QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO |
1440 |
1448 |
1441 void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, |
1449 void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, |
1442 QStaticTextItem *staticTextItem, |
1450 QStaticTextItem *staticTextItem) |
1443 bool includeMatrixInCache) |
|
1444 { |
1451 { |
1445 Q_Q(QGL2PaintEngineEx); |
1452 Q_Q(QGL2PaintEngineEx); |
1446 |
1453 |
1447 QOpenGL2PaintEngineState *s = q->state(); |
1454 QOpenGL2PaintEngineState *s = q->state(); |
1448 |
1455 |
1449 QGLTextureGlyphCache *cache = |
1456 QGLTextureGlyphCache *cache = |
1450 (QGLTextureGlyphCache *) staticTextItem->fontEngine->glyphCache(ctx, glyphType, |
1457 (QGLTextureGlyphCache *) staticTextItem->fontEngine->glyphCache(ctx, glyphType, QTransform()); |
1451 includeMatrixInCache |
|
1452 ? s->matrix |
|
1453 : QTransform()); |
|
1454 if (!cache || cache->cacheType() != glyphType) { |
1458 if (!cache || cache->cacheType() != glyphType) { |
1455 cache = new QGLTextureGlyphCache(ctx, glyphType, |
1459 cache = new QGLTextureGlyphCache(ctx, glyphType, QTransform()); |
1456 includeMatrixInCache ? s->matrix : QTransform()); |
|
1457 staticTextItem->fontEngine->setGlyphCache(ctx, cache); |
1460 staticTextItem->fontEngine->setGlyphCache(ctx, cache); |
1458 } |
1461 } |
1459 |
1462 |
1460 cache->setPaintEnginePrivate(this); |
1463 cache->setPaintEnginePrivate(this); |
1461 cache->populate(staticTextItem->fontEngine, staticTextItem->numGlyphs, staticTextItem->glyphs, |
1464 cache->populate(staticTextItem->fontEngine, staticTextItem->numGlyphs, staticTextItem->glyphs, |
1559 } |
1562 } |
1560 |
1563 |
1561 QBrush pensBrush = q->state()->pen.brush(); |
1564 QBrush pensBrush = q->state()->pen.brush(); |
1562 setBrush(pensBrush); |
1565 setBrush(pensBrush); |
1563 |
1566 |
1564 // When painting a QStaticTextItem, the glyph positions are already in device coordinates, |
|
1565 // therefore we temporarily set an identity matrix on the painter for the draw call to |
|
1566 // avoid transforming the positions twice. |
|
1567 QTransform old = s->matrix; |
|
1568 if (includeMatrixInCache) |
|
1569 s->matrix = QTransform(); |
|
1570 |
|
1571 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { |
1567 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { |
1572 |
1568 |
1573 // Subpixel antialiasing without gamma correction |
1569 // Subpixel antialiasing without gamma correction |
1574 |
1570 |
1575 QPainter::CompositionMode compMode = q->state()->composition_mode; |
1571 QPainter::CompositionMode compMode = q->state()->composition_mode; |
1662 glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, 0); |
1658 glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, 0); |
1663 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
1659 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
1664 #else |
1660 #else |
1665 glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data()); |
1661 glDrawElements(GL_TRIANGLE_STRIP, 6 * staticTextItem->numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data()); |
1666 #endif |
1662 #endif |
1667 |
|
1668 if (includeMatrixInCache) |
|
1669 s->matrix = old; |
|
1670 } |
1663 } |
1671 |
1664 |
1672 void QGL2PaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, |
1665 void QGL2PaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, |
1673 QPainter::PixmapFragmentHints hints) |
1666 QPainter::PixmapFragmentHints hints) |
1674 { |
1667 { |