diff options
author | Yoann Lopes <yoann.lopes@nokia.com> | 2012-03-16 12:09:29 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-19 18:28:52 +0100 |
commit | b271abeaf11c9fe0a05d8405f03f6a20218214ed (patch) | |
tree | 6f63cbcc6acab91e4d804c718c003c2e189d3a7d /src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp | |
parent | 3bf01de85d943432d66b5fa8048275817fd20020 (diff) |
Use a single distance-field cache instance for all sizes of a given font.
Previously we had a different cache instance for each font size, but
they all shared the same textures and positions. Only the glyph metrics
were specific to each font size.
The metrics for each font sizes are now calculated by scaling the metrics
of the distance-field size (54px).
Change-Id: I0d9016990dedd93318893506afb1dba7a5249e2e
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp index c66b82c16e..cd988c70d7 100644 --- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp @@ -151,8 +151,8 @@ void QSGDistanceFieldTextMaterialShader::updateState(const RenderState &state, Q bool updateRange = false; if (oldMaterial == 0 - || material->glyphCache()->fontScale() != oldMaterial->glyphCache()->fontScale()) { - m_fontScale = material->glyphCache()->fontScale(); + || material->fontScale() != oldMaterial->fontScale()) { + m_fontScale = material->fontScale(); updateRange = true; } if (state.isMatrixDirty()) { @@ -226,10 +226,8 @@ int QSGDistanceFieldTextMaterial::compare(const QSGMaterial *o) const const QSGDistanceFieldTextMaterial *other = static_cast<const QSGDistanceFieldTextMaterial *>(o); if (m_glyph_cache != other->m_glyph_cache) return m_glyph_cache - other->m_glyph_cache; - if (m_glyph_cache->fontScale() != other->m_glyph_cache->fontScale()) { - qreal s1 = m_glyph_cache->fontScale(); - qreal s2 = other->m_glyph_cache->fontScale(); - return int(s2 < s1) - int(s1 < s2); + if (m_fontScale != other->m_fontScale) { + return int(other->m_fontScale < m_fontScale) - int(m_fontScale < other->m_fontScale); } QRgb c1 = m_color.rgba(); QRgb c2 = other->m_color.rgba(); @@ -371,7 +369,7 @@ void DistanceFieldOutlineTextMaterialShader::updateState(const RenderState &stat QSGDistanceFieldOutlineTextMaterial *oldMaterial = static_cast<QSGDistanceFieldOutlineTextMaterial *>(oldEffect); if (oldMaterial == 0 - || material->glyphCache()->fontScale() != oldMaterial->glyphCache()->fontScale() + || material->fontScale() != oldMaterial->fontScale() || state.isMatrixDirty()) updateOutlineAlphaRange(material->glyphCache()->distanceFieldRadius()); } @@ -410,7 +408,7 @@ protected: virtual const char *vertexShader() const; virtual const char *fragmentShader() const; - void updateShift(const QSGDistanceFieldGlyphCache *cache, const QPointF& shift); + void updateShift(qreal fontScale, const QPointF& shift); int m_shift_id; }; @@ -434,17 +432,17 @@ void DistanceFieldShiftedStyleTextMaterialShader::updateState(const RenderState QSGDistanceFieldShiftedStyleTextMaterial *oldMaterial = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(oldEffect); if (oldMaterial == 0 - || oldMaterial->glyphCache()->fontScale() != material->glyphCache()->fontScale() + || oldMaterial->fontScale() != material->fontScale() || oldMaterial->shift() != material->shift() || oldMaterial->textureSize() != material->textureSize()) { - updateShift(material->glyphCache(), material->shift()); + updateShift(material->fontScale(), material->shift()); } } -void DistanceFieldShiftedStyleTextMaterialShader::updateShift(const QSGDistanceFieldGlyphCache *cache, const QPointF &shift) +void DistanceFieldShiftedStyleTextMaterialShader::updateShift(qreal fontScale, const QPointF &shift) { - QPointF texel(1.0 / cache->fontScale() * shift.x(), - 1.0 / cache->fontScale() * shift.y()); + QPointF texel(1.0 / fontScale * shift.x(), + 1.0 / fontScale * shift.y()); program()->setUniformValue(m_shift_id, texel); } @@ -639,8 +637,8 @@ void QSGHiQSubPixelDistanceFieldTextMaterialShader::updateState(const RenderStat state.context()->functions()->glBlendColor(c.redF(), c.greenF(), c.blueF(), 1.0f); } - if (oldMaterial == 0 || material->glyphCache()->fontScale() != oldMaterial->glyphCache()->fontScale()) - program()->setUniformValue(m_fontScale_id, GLfloat(material->glyphCache()->fontScale())); + if (oldMaterial == 0 || material->fontScale() != oldMaterial->fontScale()) + program()->setUniformValue(m_fontScale_id, GLfloat(material->fontScale())); if (oldMaterial == 0 || state.isMatrixDirty()) { int viewportWidth = state.viewportRect().width(); |