Performance optimization in transform node traversal.
authorTero Tiittanen <tero.tiittanen@nokia.com>
Thu, 17 Nov 2011 09:00:07 +0000 (11:00 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 17 Nov 2011 10:35:24 +0000 (11:35 +0100)
Transform node matrix calculation was modified to use the combined
matrix stack instead of matrix stack. Combined matrix stack has already
been used by clip and geometry nodes.

This improves performance because combined matrix stack stores
pointers (matrix stack stored objects). It also removes duplication of
information.

Change-Id: I1a5a2546fa9aa5a4823328dd8a321ddc42fd15a0
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>

src/declarative/scenegraph/coreapi/qsgnodeupdater.cpp
src/declarative/scenegraph/coreapi/qsgnodeupdater_p.h

index 7bf03fd..a7e5b08 100644 (file)
@@ -46,14 +46,12 @@ QT_BEGIN_NAMESPACE
 // #define QSG_UPDATER_DEBUG
 
 QSGNodeUpdater::QSGNodeUpdater()
-    : m_matrix_stack(64)
-    , m_combined_matrix_stack(64)
+    : m_combined_matrix_stack(64)
     , m_opacity_stack(64)
     , m_current_clip(0)
     , m_force_update(0)
 {
     m_opacity_stack.add(1);
-    m_matrix_stack.add(QMatrix4x4());
 }
 
 void QSGNodeUpdater::updateStates(QSGNode *n)
@@ -124,11 +122,19 @@ void QSGNodeUpdater::enterTransformNode(QSGTransformNode *t)
 #endif
 
     if (!t->matrix().isIdentity()) {
+        if (!m_combined_matrix_stack.isEmpty()) {
+            t->setCombinedMatrix(*m_combined_matrix_stack.last() * t->matrix());
+        } else {
+            t->setCombinedMatrix(t->matrix());
+        }
         m_combined_matrix_stack.add(&t->combinedMatrix());
-        m_matrix_stack.add(m_matrix_stack.last() * t->matrix());
+    } else {
+        if (!m_combined_matrix_stack.isEmpty()) {
+            t->setCombinedMatrix(*m_combined_matrix_stack.last());
+        } else {
+            t->setCombinedMatrix(QMatrix4x4());
+        }
     }
-
-    t->setCombinedMatrix(m_matrix_stack.last());
 }
 
 
@@ -142,7 +148,6 @@ void QSGNodeUpdater::leaveTransformNode(QSGTransformNode *t)
         --m_force_update;
 
     if (!t->matrix().isIdentity()) {
-        m_matrix_stack.pop_back();
         m_combined_matrix_stack.pop_back();
     }
 
index 4d2e6be..25d7c11 100644 (file)
@@ -72,7 +72,6 @@ protected:
     void visitChildren(QSGNode *n);
 
 
-    QDataBuffer<QMatrix4x4> m_matrix_stack;
     QDataBuffer<const QMatrix4x4 *> m_combined_matrix_stack;
     QDataBuffer<qreal> m_opacity_stack;
     const QSGClipNode *m_current_clip;