Commit fd802851 authored by Yoann Lopes's avatar Yoann Lopes Committed by Qt by Nokia

Don't register sub distance field glyph nodes with the glyph cache.

The original distance field glyph node takes care of the glyphs
reference counting. The potential sub glyph nodes created when the
glyphs are in another texture are note registered anymore with the cache
and don't reference count their glyphs.
Also got rid of unnecessary data members.

Change-Id: I1544792d5d896c6de26e0838e4f80397759ea012
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
parent dfdea38c
...@@ -47,7 +47,8 @@ ...@@ -47,7 +47,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
QSGDistanceFieldGlyphNode::QSGDistanceFieldGlyphNode(QSGContext *context) QSGDistanceFieldGlyphNode::QSGDistanceFieldGlyphNode(QSGContext *context)
: m_context(context) : m_glyphNodeType(RootGlyphNode)
, m_context(context)
, m_material(0) , m_material(0)
, m_glyph_cache(0) , m_glyph_cache(0)
, m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0) , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
...@@ -69,15 +70,17 @@ QSGDistanceFieldGlyphNode::~QSGDistanceFieldGlyphNode() ...@@ -69,15 +70,17 @@ QSGDistanceFieldGlyphNode::~QSGDistanceFieldGlyphNode()
{ {
delete m_material; delete m_material;
if (m_glyphNodeType == SubGlyphNode)
return;
if (m_glyph_cache) { if (m_glyph_cache) {
m_glyph_cache->release(m_glyphs.glyphIndexes()); m_glyph_cache->release(m_glyphs.glyphIndexes());
m_glyph_cache->unregisterGlyphNode(this); m_glyph_cache->unregisterGlyphNode(this);
m_glyph_cache->unregisterOwnerElement(ownerElement()); m_glyph_cache->unregisterOwnerElement(ownerElement());
} }
for (int i = 0; i < m_nodesToDelete.count(); ++i) while (m_nodesToDelete.count())
delete m_nodesToDelete.at(i); delete m_nodesToDelete.takeLast();
m_nodesToDelete.clear();
} }
void QSGDistanceFieldGlyphNode::setColor(const QColor &color) void QSGDistanceFieldGlyphNode::setColor(const QColor &color)
...@@ -106,8 +109,15 @@ void QSGDistanceFieldGlyphNode::setGlyphs(const QPointF &position, const QGlyphR ...@@ -106,8 +109,15 @@ void QSGDistanceFieldGlyphNode::setGlyphs(const QPointF &position, const QGlyphR
m_position = QPointF(position.x(), position.y() - font.ascent()); m_position = QPointF(position.x(), position.y() - font.ascent());
m_glyphs = glyphs; m_glyphs = glyphs;
m_dirtyGeometry = true;
m_dirtyMaterial = true;
QSGDistanceFieldGlyphCache *oldCache = m_glyph_cache; QSGDistanceFieldGlyphCache *oldCache = m_glyph_cache;
m_glyph_cache = m_context->distanceFieldGlyphCache(m_glyphs.rawFont()); m_glyph_cache = m_context->distanceFieldGlyphCache(m_glyphs.rawFont());
if (m_glyphNodeType == SubGlyphNode)
return;
if (m_glyph_cache != oldCache) { if (m_glyph_cache != oldCache) {
Q_ASSERT(ownerElement() != 0); Q_ASSERT(ownerElement() != 0);
if (oldCache) { if (oldCache) {
...@@ -122,9 +132,6 @@ void QSGDistanceFieldGlyphNode::setGlyphs(const QPointF &position, const QGlyphR ...@@ -122,9 +132,6 @@ void QSGDistanceFieldGlyphNode::setGlyphs(const QPointF &position, const QGlyphR
const QVector<quint32> glyphIndexes = m_glyphs.glyphIndexes(); const QVector<quint32> glyphIndexes = m_glyphs.glyphIndexes();
for (int i = 0; i < glyphIndexes.count(); ++i) for (int i = 0; i < glyphIndexes.count(); ++i)
m_allGlyphIndexesLookup.insert(glyphIndexes.at(i)); m_allGlyphIndexesLookup.insert(glyphIndexes.at(i));
m_dirtyGeometry = true;
m_dirtyMaterial = true;
} }
void QSGDistanceFieldGlyphNode::setStyle(QQuickText::TextStyle style) void QSGDistanceFieldGlyphNode::setStyle(QQuickText::TextStyle style)
...@@ -153,9 +160,8 @@ void QSGDistanceFieldGlyphNode::preprocess() ...@@ -153,9 +160,8 @@ void QSGDistanceFieldGlyphNode::preprocess()
{ {
Q_ASSERT(m_glyph_cache); Q_ASSERT(m_glyph_cache);
for (int i = 0; i < m_nodesToDelete.count(); ++i) while (m_nodesToDelete.count())
delete m_nodesToDelete.at(i); delete m_nodesToDelete.takeLast();
m_nodesToDelete.clear();
m_glyph_cache->processPendingGlyphs(); m_glyph_cache->processPendingGlyphs();
m_glyph_cache->update(); m_glyph_cache->update();
...@@ -182,14 +188,15 @@ void QSGDistanceFieldGlyphNode::updateGeometry() ...@@ -182,14 +188,15 @@ void QSGDistanceFieldGlyphNode::updateGeometry()
Q_ASSERT(m_glyph_cache); Q_ASSERT(m_glyph_cache);
// Remove previously created sub glyph nodes // Remove previously created sub glyph nodes
QHash<const QSGDistanceFieldGlyphCache::Texture *, QSGDistanceFieldGlyphNode *>::iterator it = m_subNodes.begin(); // We assume all the children are sub glyph nodes
while (it != m_subNodes.end()) { QSGNode *subnode = firstChild();
removeChildNode(it.value()); while (subnode) {
// We can't delete the node now as it might be in the preprocess list // We can't delete the node now as it might be in the preprocess list
// It will be deleted in the next preprocess // It will be deleted in the next preprocess
m_nodesToDelete.append(it.value()); m_nodesToDelete.append(subnode);
it = m_subNodes.erase(it); subnode = subnode->nextSibling();
} }
removeAllChildNodes();
QSGGeometry *g = geometry(); QSGGeometry *g = geometry();
...@@ -287,25 +294,19 @@ void QSGDistanceFieldGlyphNode::updateGeometry() ...@@ -287,25 +294,19 @@ void QSGDistanceFieldGlyphNode::updateGeometry()
QHash<const QSGDistanceFieldGlyphCache::Texture *, GlyphInfo>::const_iterator ite = glyphsInOtherTextures.constBegin(); QHash<const QSGDistanceFieldGlyphCache::Texture *, GlyphInfo>::const_iterator ite = glyphsInOtherTextures.constBegin();
while (ite != glyphsInOtherTextures.constEnd()) { while (ite != glyphsInOtherTextures.constEnd()) {
QHash<const QSGDistanceFieldGlyphCache::Texture *, QSGDistanceFieldGlyphNode *>::iterator subIt = m_subNodes.find(ite.key());
if (subIt == m_subNodes.end()) {
QSGDistanceFieldGlyphNode *subNode = new QSGDistanceFieldGlyphNode(m_context);
subNode->setOwnerElement(m_ownerElement);
subNode->setColor(m_color);
subNode->setStyle(m_style);
subNode->setStyleColor(m_styleColor);
subNode->update();
appendChildNode(subNode);
subIt = m_subNodes.insert(ite.key(), subNode);
}
QGlyphRun subNodeGlyphRun(m_glyphs); QGlyphRun subNodeGlyphRun(m_glyphs);
subNodeGlyphRun.setGlyphIndexes(ite->indexes); subNodeGlyphRun.setGlyphIndexes(ite->indexes);
subNodeGlyphRun.setPositions(ite->positions); subNodeGlyphRun.setPositions(ite->positions);
subIt.value()->setGlyphs(m_originalPosition, subNodeGlyphRun); QSGDistanceFieldGlyphNode *subNode = new QSGDistanceFieldGlyphNode(m_context);
subIt.value()->update(); subNode->setGlyphNodeType(SubGlyphNode);
subIt.value()->updateGeometry(); // we have to explicity call this now as preprocess won't be called before it's rendered subNode->setColor(m_color);
subNode->setStyle(m_style);
subNode->setStyleColor(m_styleColor);
subNode->setGlyphs(m_originalPosition, subNodeGlyphRun);
subNode->update();
subNode->updateGeometry(); // we have to explicity call this now as preprocess won't be called before it's rendered
appendChildNode(subNode);
++ite; ++ite;
} }
......
...@@ -77,8 +77,15 @@ public: ...@@ -77,8 +77,15 @@ public:
void updateGeometry(); void updateGeometry();
private: private:
enum DistanceFieldGlyphNodeType {
RootGlyphNode,
SubGlyphNode
};
void setGlyphNodeType(DistanceFieldGlyphNodeType type) { m_glyphNodeType = type; }
void updateMaterial(); void updateMaterial();
DistanceFieldGlyphNodeType m_glyphNodeType;
QColor m_color; QColor m_color;
QPointF m_baseLine; QPointF m_baseLine;
QSGContext *m_context; QSGContext *m_context;
...@@ -93,8 +100,7 @@ private: ...@@ -93,8 +100,7 @@ private:
AntialiasingMode m_antialiasingMode; AntialiasingMode m_antialiasingMode;
QRectF m_boundingRect; QRectF m_boundingRect;
const QSGDistanceFieldGlyphCache::Texture *m_texture; const QSGDistanceFieldGlyphCache::Texture *m_texture;
QHash<const QSGDistanceFieldGlyphCache::Texture *, QSGDistanceFieldGlyphNode *> m_subNodes; QLinkedList<QSGNode *> m_nodesToDelete;
QList<QSGDistanceFieldGlyphNode *> m_nodesToDelete;
struct GlyphInfo { struct GlyphInfo {
QVector<quint32> indexes; QVector<quint32> indexes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment