Avoid unnecessary updates when using in-process cache
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Thu, 1 Mar 2012 10:24:57 +0000 (11:24 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 1 Mar 2012 11:22:00 +0000 (12:22 +0100)
Whenever an in-process cache is updated, it will emit
itemsAvailable() signals to all listening glyph caches. This will
in turn cause each of the glyph caches to update and each
of the glyph nodes to be preprocessed (the entire scene graph will
be updated.) This happens even if the changes to the in-process
cache are requested by an external client, due to a cross-process
cache sharing mechanism. However, itemsAvailable() signals are
only interesting if the items were requested by the in-process
cache.

We therefore add a mechanism now to check if the glyphs were actually
requested by the cache before updating anything.

Change-Id: I529f94b3928c2a5e06fec354014fa11d21671057
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>

src/quick/scenegraph/qsgshareddistancefieldglyphcache.cpp
src/quick/scenegraph/qsgshareddistancefieldglyphcache_p.h

index e762898..951ee21 100644 (file)
@@ -90,7 +90,7 @@ QSGSharedDistanceFieldGlyphCache::QSGSharedDistanceFieldGlyphCache(const QByteAr
             this, SLOT(reportItemsAvailable(QByteArray,void*,QSize,QVector<quint32>,QVector<QPoint>)),
             Qt::DirectConnection);
     connect(sharedGraphicsCache, SIGNAL(itemsUpdated(QByteArray,void*,QSize,QVector<quint32>,QVector<QPoint>)),
-            this, SLOT(reportItemsAvailable(QByteArray,void*,QSize,QVector<quint32>,QVector<QPoint>)),
+            this, SLOT(reportItemsUpdated(QByteArray,void*,QSize,QVector<quint32>,QVector<QPoint>)),
             Qt::DirectConnection);
     connect(sharedGraphicsCache, SIGNAL(itemsInvalidated(QByteArray,QVector<quint32>)),
             this, SLOT(reportItemsInvalidated(QByteArray,QVector<quint32>)),
@@ -542,9 +542,38 @@ void QSGSharedDistanceFieldGlyphCache::processPendingGlyphs()
 }
 
 void QSGSharedDistanceFieldGlyphCache::reportItemsAvailable(const QByteArray &cacheId,
-                                                        void *bufferId, const QSize &bufferSize,
-                                                        const QVector<quint32> &itemIds,
-                                                        const QVector<QPoint> &positions)
+                                                            void *bufferId,
+                                                            const QSize &bufferSize,
+                                                            const QVector<quint32> &itemIds,
+                                                            const QVector<QPoint> &positions)
+{
+    bool requestedItemsInList = false;
+    {
+        QMutexLocker locker(&m_pendingGlyphsMutex);
+        if (m_cacheId != cacheId)
+            return;
+
+#if defined(QSGSHAREDDISTANCEFIELDGLYPHCACHE_DEBUG)
+            qDebug("QSGSharedDistanceFieldGlyphCache::reportItemsAvailable() called for %s (%d glyphs, bufferSize: %dx%d)",
+                   cacheId.constData(), itemIds.size(), bufferSize.width(), bufferSize.height());
+#endif
+
+        for (int i=0; i<itemIds.size(); ++i) {
+            if (m_requestedGlyphsThatHaveNotBeenReturned.contains(itemIds.at(i))) {
+                requestedItemsInList = true;
+                break;
+            }
+        }
+    }
+
+    if (requestedItemsInList)
+        reportItemsUpdated(cacheId, bufferId, bufferSize, itemIds, positions);
+}
+
+void QSGSharedDistanceFieldGlyphCache::reportItemsUpdated(const QByteArray &cacheId,
+                                                          void *bufferId, const QSize &bufferSize,
+                                                          const QVector<quint32> &itemIds,
+                                                          const QVector<QPoint> &positions)
 {
     {
         QMutexLocker locker(&m_pendingGlyphsMutex);
@@ -554,7 +583,7 @@ void QSGSharedDistanceFieldGlyphCache::reportItemsAvailable(const QByteArray &ca
         Q_ASSERT(itemIds.size() == positions.size());
 
 #if defined(QSGSHAREDDISTANCEFIELDGLYPHCACHE_DEBUG)
-        qDebug("QSGSharedDistanceFieldGlyphCache::reportItemsAvailable() called for %s (%d glyphs, bufferSize: %dx%d)",
+        qDebug("QSGSharedDistanceFieldGlyphCache::reportItemsUpdated() called for %s (%d glyphs, bufferSize: %dx%d)",
                cacheId.constData(), itemIds.size(), bufferSize.width(), bufferSize.height());
 #endif
 
index cadf4bc..8250b97 100644 (file)
@@ -78,6 +78,8 @@ private Q_SLOTS:
     void reportItemsAvailable(const QByteArray &cacheId,
                           void *bufferId, const QSize &bufferSize,
                           const QVector<quint32> &itemIds, const QVector<QPoint> &positions);
+    void reportItemsUpdated(const QByteArray &cacheId, void *bufferId, const QSize &bufferSize,
+                            const QVector<quint32> &itemIds, const QVector<QPoint> &positions);
     void reportItemsInvalidated(const QByteArray &cacheId, const QVector<quint32> &itemIds);
 
 private: