diff options
-rw-r--r-- | src/quick/scenegraph/qsgadaptationlayer.cpp | 16 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgadaptationlayer_p.h | 1 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/quick/scenegraph/qsgadaptationlayer.cpp b/src/quick/scenegraph/qsgadaptationlayer.cpp index 4232bf125c..4f5c4efe14 100644 --- a/src/quick/scenegraph/qsgadaptationlayer.cpp +++ b/src/quick/scenegraph/qsgadaptationlayer.cpp @@ -62,7 +62,9 @@ QSGDistanceFieldGlyphCache::QSGDistanceFieldGlyphCache(QSGDistanceFieldGlyphCach m_doubleGlyphResolution = qt_fontHasNarrowOutlines(font) && m_glyphCount < QT_DISTANCEFIELD_HIGHGLYPHCOUNT; m_referenceFont = font; - m_referenceFont.setPixelSize(QT_DISTANCEFIELD_BASEFONTSIZE(m_doubleGlyphResolution)); + // we set the same pixel size as used by the distance field internally. + // this allows us to call pathForGlyph once and reuse the result. + m_referenceFont.setPixelSize(QT_DISTANCEFIELD_BASEFONTSIZE(m_doubleGlyphResolution) * QT_DISTANCEFIELD_SCALE(m_doubleGlyphResolution)); Q_ASSERT(m_referenceFont.isValid()); m_coreProfile = (c->format().profile() == QSurfaceFormat::CoreProfile); @@ -78,8 +80,12 @@ QSGDistanceFieldGlyphCache::GlyphData &QSGDistanceFieldGlyphCache::glyphData(gly if (data == m_glyphsData.end()) { GlyphData gd; gd.texture = &s_emptyTexture; - QPainterPath path = m_referenceFont.pathForGlyph(glyph); - gd.boundingRect = path.boundingRect(); + gd.path = m_referenceFont.pathForGlyph(glyph); + // need bounding rect in base font size scale + qreal scaleFactor = qreal(1) / QT_DISTANCEFIELD_SCALE(m_doubleGlyphResolution); + QTransform scaleDown; + scaleDown.scale(scaleFactor, scaleFactor); + gd.boundingRect = scaleDown.mapRect(gd.path.boundingRect()); data = m_glyphsData.insert(glyph, gd); } return data.value(); @@ -160,9 +166,11 @@ void QSGDistanceFieldGlyphCache::update() QList<QDistanceField> distanceFields; for (int i = 0; i < m_pendingGlyphs.size(); ++i) { - distanceFields.append(QDistanceField(m_referenceFont, + GlyphData &gd = glyphData(m_pendingGlyphs.at(i)); + distanceFields.append(QDistanceField(gd.path, m_pendingGlyphs.at(i), m_doubleGlyphResolution)); + gd.path = QPainterPath(); // no longer needed, so release memory used by the painter path } qint64 renderTime = 0; diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h index e5923fc564..1253711a94 100644 --- a/src/quick/scenegraph/qsgadaptationlayer_p.h +++ b/src/quick/scenegraph/qsgadaptationlayer_p.h @@ -323,6 +323,7 @@ protected: Texture *texture; TexCoord texCoord; QRectF boundingRect; + QPainterPath path; quint32 ref; GlyphData() : texture(0), ref(0) { } |