diff options
author | Jere Tuliniemi <jere.tuliniemi@qt.io> | 2019-06-06 11:31:53 +0300 |
---|---|---|
committer | Jere Tuliniemi <jere.tuliniemi@qt.io> | 2019-06-06 12:08:23 +0300 |
commit | 170a30e872f8ac6a0b0bef226362105472f3f984 (patch) | |
tree | 5ca138a6b8577b2ad332e05372895dad7bf10f49 | |
parent | ac8b2f7c7b2db8860f8414175e1509b6361f3634 (diff) |
Copy memory leak fixes from Qt3D runtime
Copies "Work around memory leak in QRawFont::setPixelSize()" and
"Fix minor memory leak".
Task-number: QT3DS-3617
Change-Id: I7e669a303fc1c2d099bc5383fdd78720f88a8f9e
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r-- | src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldGlyphCache.cpp | 1 | ||||
-rw-r--r-- | src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp | 21 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldGlyphCache.cpp b/src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldGlyphCache.cpp index 3779aa56..e9453350 100644 --- a/src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldGlyphCache.cpp +++ b/src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldGlyphCache.cpp @@ -68,6 +68,7 @@ Q3DSDistanceFieldGlyphCache::~Q3DSDistanceFieldGlyphCache() { for (auto &texture : m_textures) qt3ds::foundation::NVDelete(m_context.GetAllocator(), texture.texture); + delete m_areaAllocator; } int Q3DSDistanceFieldGlyphCache::maxTextureSize() const diff --git a/src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp b/src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp index 290964b2..8c1b28af 100644 --- a/src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp +++ b/src/Runtime/ogl-runtime/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp @@ -119,10 +119,12 @@ Q3DSDistanceFieldRenderer::buildGlyphsPerTexture(const SText &textInfo) bool hasValidBoundingBox = boundingBox.x() > 0 || boundingBox.y() > 0; QRawFont font = m_fontDatabase.findFont(textInfo.m_Font.c_str()); - font.setPixelSize(qreal(textInfo.m_FontSize)); + qreal scaleFactor = font.pixelSize() / qreal(textInfo.m_FontSize); - const qreal maximumWidth = boundingBox.isNull() ? qreal(0x01000000) : qreal(boundingBox.x()); - const qreal maximumHeight = boundingBox.isNull() ? qreal(0x01000000) : qreal(boundingBox.y()); + const qreal maximumWidth = boundingBox.isNull() ? qreal(0x01000000) + : qreal(boundingBox.x()) * scaleFactor; + const qreal maximumHeight = boundingBox.isNull() ? qreal(0x01000000) + : qreal(boundingBox.y()) * scaleFactor; QTextLayout layout; QTextOption option = layout.textOption(); @@ -159,9 +161,9 @@ Q3DSDistanceFieldRenderer::buildGlyphsPerTexture(const SText &textInfo) layout.clearLayout(); - float leading = textInfo.m_Leading; + qreal leading = qreal(textInfo.m_Leading) * scaleFactor; width = 0.0; - height = qreal(-leading); + height = -leading; QVector<QTextLayout::FormatRange> formatRanges; @@ -169,7 +171,7 @@ Q3DSDistanceFieldRenderer::buildGlyphsPerTexture(const SText &textInfo) formatRange.start = 0; formatRange.length = text.length(); formatRange.format.setFontLetterSpacingType(QFont::AbsoluteSpacing); - formatRange.format.setFontLetterSpacing(qreal(textInfo.m_Tracking)); + formatRange.format.setFontLetterSpacing(qreal(textInfo.m_Tracking) * scaleFactor); formatRanges.append(formatRange); layout.setFormats(formatRanges); @@ -183,7 +185,7 @@ Q3DSDistanceFieldRenderer::buildGlyphsPerTexture(const SText &textInfo) break; line.setLineWidth(maximumWidth); - height += qreal(leading); + height += leading; height = qCeil(height); qreal textWidth = line.naturalTextWidth(); @@ -381,6 +383,11 @@ Q3DSDistanceFieldRenderer::buildGlyphsPerTexture(const SText &textInfo) float cy1 = float(position.y() - metrics.baselineY) + offsetY; float cy2 = cy1 + float(metrics.height); + cx1 /= float(scaleFactor); + cy1 /= float(scaleFactor); + cx2 /= float(scaleFactor); + cy2 /= float(scaleFactor); + if (textInfo.m_DropShadow) { if (shadowOffsetX < 0.0) cx1 += float(shadowOffsetX * fontScale); |