diff options
author | Andy Nichols <andy.nichols@qt.io> | 2017-02-27 13:50:32 +0100 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2017-02-28 19:21:00 +0000 |
commit | 9bd2705a2f02d1c54f179aa096142c151046c642 (patch) | |
tree | 6bcdc3968cb477e5161e5713502ae02a877b1711 /src/plugins | |
parent | c67d33db5b4e78027181be492d4757ac786e5c1f (diff) |
OpenVG: Fix glyph cache to actually ref count
In my haste to add the code to cleanup unused glyphs I neglected to add
the coded needed to ref count the glyphs. So glyphs that were being
used more than once were getting removed too early.
Change-Id: If3fa083313c345beac6705956067bee0932f7f60
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp | 25 | ||||
-rw-r--r-- | src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h | 3 |
2 files changed, 15 insertions, 13 deletions
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp b/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp index dd630c776f..df47e920af 100644 --- a/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp +++ b/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp @@ -94,7 +94,7 @@ void QSGOpenVGFontGlyphCache::populate(const QVector<quint32> &glyphs) referencedGlyphs.insert(glyphIndex); - if (!m_cachedGlyphs.contains(glyphIndex)) { + if (!m_glyphReferences.contains(glyphIndex)) { newGlyphs.insert(glyphIndex); } } @@ -119,17 +119,9 @@ void QSGOpenVGFontGlyphCache::requestGlyphs(const QSet<quint32> &glyphs) { VGfloat origin[2]; VGfloat escapement[2]; - QRectF metrics; QRawFont rawFont = m_referenceFont; - // Before adding any new glyphs, remove any unused glyphs - for (auto glyph : qAsConst(m_unusedGlyphs)) { - vgClearGlyph(m_font, glyph); - } - for (auto glyph : glyphs) { - m_cachedGlyphs.insert(glyph); - // Calculate the path for the glyph and cache it. QPainterPath path = rawFont.pathForGlyph(glyph); VGPath vgPath; @@ -151,12 +143,23 @@ void QSGOpenVGFontGlyphCache::requestGlyphs(const QSet<quint32> &glyphs) void QSGOpenVGFontGlyphCache::referenceGlyphs(const QSet<quint32> &glyphs) { - m_unusedGlyphs -= glyphs; + for (auto glyph : glyphs) { + if (m_glyphReferences.contains(glyph)) + m_glyphReferences[glyph] += 1; + else + m_glyphReferences.insert(glyph, 1); + } } void QSGOpenVGFontGlyphCache::releaseGlyphs(const QSet<quint32> &glyphs) { - m_unusedGlyphs += glyphs; + for (auto glyph : glyphs) { + int references = m_glyphReferences[glyph] -= 1; + if (references == 0) { + vgClearGlyph(m_font, glyph); + m_glyphReferences.remove(glyph); + } + } } QT_END_NAMESPACE diff --git a/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h b/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h index a88d28b0fe..107ec0c892 100644 --- a/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h +++ b/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h @@ -87,8 +87,7 @@ private: int m_glyphCount; VGFont m_font; - QSet<quint32> m_cachedGlyphs; - QSet<quint32> m_unusedGlyphs; + QHash<quint32, int> m_glyphReferences; }; |