From a9b1594576579044c26ef325191a79ffe1df7e27 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Mon, 18 Jul 2011 13:17:46 +0200 Subject: [PATCH] Fixed QSGDistanceFieldGlyphNode initialization order. Change-Id: Id2e8ccf6441ce7e7a2bcdd6f0d50745e7d9ba653 Reviewed-on: http://codereview.qt.nokia.com/1750 Reviewed-by: Qt Sanity Bot Reviewed-by: Yoann Lopes --- src/declarative/items/qsgtextnode.cpp | 6 +++- src/declarative/scenegraph/qsgadaptationlayer_p.h | 2 + src/declarative/scenegraph/qsgdefaultglyphnode_p.h | 2 + .../scenegraph/qsgdistancefieldglyphnode.cpp | 34 +++++++++++++++----- .../scenegraph/qsgdistancefieldglyphnode_p.h | 6 +++ 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/declarative/items/qsgtextnode.cpp b/src/declarative/items/qsgtextnode.cpp index 2eb705f..d36db1b 100644 --- a/src/declarative/items/qsgtextnode.cpp +++ b/src/declarative/items/qsgtextnode.cpp @@ -162,9 +162,13 @@ QSGGlyphNode *QSGTextNode::addGlyphs(const QPointF &position, const QGlyphRun &g dfNode->setStyleColor(styleColor); } node->setColor(color); - appendChildNode(node); } + node->update(); + + if (node != prevNode) + appendChildNode(node); + return node; } diff --git a/src/declarative/scenegraph/qsgadaptationlayer_p.h b/src/declarative/scenegraph/qsgadaptationlayer_p.h index 33f664f..81b17a9 100644 --- a/src/declarative/scenegraph/qsgadaptationlayer_p.h +++ b/src/declarative/scenegraph/qsgadaptationlayer_p.h @@ -112,6 +112,8 @@ public: virtual void setPreferredAntialiasingMode(AntialiasingMode) = 0; + virtual void update() = 0; + protected: QRectF m_bounding_rect; }; diff --git a/src/declarative/scenegraph/qsgdefaultglyphnode_p.h b/src/declarative/scenegraph/qsgdefaultglyphnode_p.h index 8d79d11..16e267b 100644 --- a/src/declarative/scenegraph/qsgdefaultglyphnode_p.h +++ b/src/declarative/scenegraph/qsgdefaultglyphnode_p.h @@ -65,6 +65,8 @@ public: virtual void setPreferredAntialiasingMode(AntialiasingMode) { } + virtual void update() { } + private: QGlyphRun m_glyphs; QPointF m_position; diff --git a/src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp b/src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp index 343487b..26326d0 100644 --- a/src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp +++ b/src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp @@ -52,6 +52,9 @@ QSGDistanceFieldGlyphNode::QSGDistanceFieldGlyphNode() , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0) , m_style(QSGText::Normal) , m_antialiasingMode(GrayAntialiasing) + , m_dirtyFont(false) + , m_dirtyGeometry(false) + , m_dirtyMaterial(false) { m_geometry.setDrawingMode(GL_TRIANGLES); setGeometry(&m_geometry); @@ -84,7 +87,7 @@ void QSGDistanceFieldGlyphNode::setPreferredAntialiasingMode(AntialiasingMode mo if (mode == m_antialiasingMode) return; m_antialiasingMode = mode; - updateMaterial(); + m_dirtyMaterial = true; } void QSGDistanceFieldGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyphs) @@ -93,23 +96,35 @@ void QSGDistanceFieldGlyphNode::setGlyphs(const QPointF &position, const QGlyphR m_position = QPointF(position.x(), position.y() - font.ascent()); m_glyphs = glyphs; - updateFont(); - updateGeometry(); - updateMaterial(); - -#ifdef QML_RUNTIME_TESTING - description = QLatin1String("glyphs"); -#endif + m_dirtyFont = true; + m_dirtyGeometry = true; + m_dirtyMaterial = true; } void QSGDistanceFieldGlyphNode::setStyle(QSGText::TextStyle style) { + if (m_style == style) + return; m_style = style; + m_dirtyMaterial = true; } void QSGDistanceFieldGlyphNode::setStyleColor(const QColor &color) { + if (m_styleColor == color) + return; m_styleColor = color; + m_dirtyMaterial = true; +} + +void QSGDistanceFieldGlyphNode::update() +{ + if (m_dirtyFont) + updateFont(); + if (m_dirtyGeometry) + updateGeometry(); + if (m_dirtyMaterial) + updateMaterial(); } void QSGDistanceFieldGlyphNode::updateGeometry() @@ -225,11 +240,13 @@ void QSGDistanceFieldGlyphNode::updateGeometry() setBoundingRect(boundingRect); markDirty(DirtyGeometry); + m_dirtyGeometry = false; } void QSGDistanceFieldGlyphNode::updateFont() { m_glyph_cache = QSGDistanceFieldGlyphCache::get(QGLContext::currentContext(), m_glyphs.rawFont()); + m_dirtyFont = false; } void QSGDistanceFieldGlyphNode::updateMaterial() @@ -260,6 +277,7 @@ void QSGDistanceFieldGlyphNode::updateMaterial() m_material->setGlyphCache(m_glyph_cache); m_material->setColor(m_color); setMaterial(m_material); + m_dirtyMaterial = false; } QT_END_NAMESPACE diff --git a/src/declarative/scenegraph/qsgdistancefieldglyphnode_p.h b/src/declarative/scenegraph/qsgdistancefieldglyphnode_p.h index 5d6ddd0..926a843 100644 --- a/src/declarative/scenegraph/qsgdistancefieldglyphnode_p.h +++ b/src/declarative/scenegraph/qsgdistancefieldglyphnode_p.h @@ -69,6 +69,8 @@ public: void setStyle(QSGText::TextStyle style); void setStyleColor(const QColor &color); + virtual void update(); + private: void updateGeometry(); void updateFont(); @@ -84,6 +86,10 @@ private: QSGText::TextStyle m_style; QColor m_styleColor; AntialiasingMode m_antialiasingMode; + + uint m_dirtyFont: 1; + uint m_dirtyGeometry: 1; + uint m_dirtyMaterial: 1; }; QT_END_HEADER -- 1.7.2.5