glyphIndexes.append(m_allGlyphs.at(i).glyphIndex);
m_glyph_cache->release(glyphIndexes);
m_glyph_cache->unregisterGlyphNode(this);
+ m_glyph_cache->unregisterOwnerElement(ownerElement());
}
for (int i = 0; i < m_nodesToDelete.count(); ++i)
void QSGSharedDistanceFieldGlyphCache::registerOwnerElement(QQuickItem *ownerElement)
{
- bool ok = connect(this, SIGNAL(glyphsPending()), ownerElement, SLOT(triggerPreprocess()));
- Q_ASSERT_X(ok, Q_FUNC_INFO, "QML element that owns a glyph node must have triggerPreprocess() slot");
- Q_UNUSED(ok);
+ Owner &owner = m_registeredOwners[ownerElement];
+ if (owner.ref == 0) {
+ owner.item = ownerElement;
+
+ bool ok = connect(this, SIGNAL(glyphsPending()), ownerElement, SLOT(triggerPreprocess()));
+ Q_ASSERT_X(ok, Q_FUNC_INFO, "QML element that owns a glyph node must have triggerPreprocess() slot");
+ Q_UNUSED(ok);
+ }
+ ++owner.ref;
}
void QSGSharedDistanceFieldGlyphCache::unregisterOwnerElement(QQuickItem *ownerElement)
{
- disconnect(this, SIGNAL(glyphsPending()), ownerElement, SLOT(triggerPreprocess()));
+ QHash<QQuickItem *, Owner>::iterator it = m_registeredOwners.find(ownerElement);
+ if (it != m_registeredOwners.end() && --it->ref <= 0) {
+ if (it->item)
+ disconnect(this, SIGNAL(glyphsPending()), ownerElement, SLOT(triggerPreprocess()));
+ m_registeredOwners.erase(it);
+ }
}
#if defined(QSGSHAREDDISTANCEFIELDGLYPHCACHE_DEBUG_)
#include <QtCore/qwaitcondition.h>
#include <private/qsgadaptationlayer_p.h>
+#include <private/qqmlguard_p.h>
QT_BEGIN_HEADER
QPoint position;
};
+ struct Owner
+ {
+ Owner() : ref(0) {}
+ Owner(const Owner &o) : item(o.item), ref(o.ref) {}
+ Owner &operator =(const Owner &o) { item = o.item; ref = o.ref; return *this; }
+
+ QQmlGuard<QQuickItem> item;
+ int ref;
+ };
+
QHash<quint32, PendingGlyph> m_pendingReadyGlyphs;
QHash<glyph_t, void *> m_bufferForGlyph;
+ QHash<QQuickItem *, Owner> m_registeredOwners;
};
QT_END_NAMESPACE