Support opt-in QSGNode descriptions without breaking binary compat.
authorGunnar Sletta <gunnar.sletta@digia.com>
Fri, 2 Aug 2013 19:04:44 +0000 (21:04 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 12 Aug 2013 08:46:41 +0000 (10:46 +0200)
This define is quite useful for debugging scene graph internals, but
it is disabled by default to conserve memory.

For clarity, I renamed the define to QSG_RUNTIME_DESCRIPTION.

Change-Id: Ie5ff44d67af38adc65d0d09255d8533dc7a33bff
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
13 files changed:
src/quick/items/qquickitem_p.h
src/quick/items/qquickshadereffectnode.cpp
src/quick/items/qquicktextnode.cpp
src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp
src/quick/scenegraph/coreapi/qsgnode.cpp
src/quick/scenegraph/coreapi/qsgnode.h
src/quick/scenegraph/coreapi/qsgnode_p.h
src/quick/scenegraph/coreapi/qsgrenderer.cpp
src/quick/scenegraph/qsgdefaultglyphnode.cpp
src/quick/scenegraph/qsgdefaultimagenode.cpp
src/quick/scenegraph/qsgdefaultrectanglenode.cpp
src/quick/scenegraph/qsgdistancefieldglyphnode.cpp
src/quick/scenegraph/util/qsgsimpletexturenode.cpp

index 0ffc092..fe70b38 100644 (file)
@@ -867,9 +867,9 @@ QSGTransformNode *QQuickItemPrivate::itemNode()
     if (!itemNodeInstance) {
         itemNodeInstance = createTransformNode();
         itemNodeInstance->setFlag(QSGNode::OwnedByParent, false);
-#ifdef QML_RUNTIME_TESTING
+#ifdef QSG_RUNTIME_DESCRIPTION
         Q_Q(QQuickItem);
-        itemNodeInstance->description = QString::fromLatin1("QQuickItem(%1)").arg(QString::fromLatin1(q->metaObject()->className()));
+        qsgnode_set_description(itemNodeInstance, QString::fromLatin1("QQuickItem(%1)").arg(QString::fromLatin1(q->metaObject()->className())));
 #endif
     }
     return itemNodeInstance;
@@ -887,8 +887,8 @@ QSGNode *QQuickItemPrivate::childContainerNode()
             opacityNode()->appendChildNode(groupNode);
         else
             itemNode()->appendChildNode(groupNode);
-#ifdef QML_RUNTIME_TESTING
-        groupNode->description = QLatin1String("group");
+#ifdef QSG_RUNTIME_DESCRIPTION
+        qsgnode_set_description(groupNode, QLatin1String("group"));
 #endif
     }
     return groupNode;
index 17c5e4c..d2a6184 100644 (file)
@@ -390,8 +390,8 @@ QQuickShaderEffectNode::QQuickShaderEffectNode()
 {
     QSGNode::setFlag(UsePreprocess, true);
 
-#ifdef QML_RUNTIME_TESTING
-    description = QLatin1String("shadereffect");
+#ifdef QSG_RUNTIME_DESCRIPTION
+    qsgnode_set_description(this, QLatin1String("shadereffect"));
 #endif
 }
 
index d8040a1..d3a566f 100644 (file)
@@ -83,8 +83,8 @@ namespace {
 QQuickTextNode::QQuickTextNode(QSGContext *context, QQuickItem *ownerElement)
     : m_context(context), m_cursorNode(0), m_ownerElement(ownerElement), m_useNativeRenderer(false)
 {
-#if defined(QML_RUNTIME_TESTING)
-    description = QLatin1String("text");
+#ifdef QSG_RUNTIME_DESCRIPTION
+    qsgnode_set_description(this, QLatin1String("text"));
 #endif
 }
 
index 448ec55..a343a81 100644 (file)
@@ -156,13 +156,11 @@ void QSGDefaultRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyState state)
 
 void QSGDefaultRenderer::render()
 {
-#if defined (QML_RUNTIME_TESTING)
     static bool dumpTree = qApp->arguments().contains(QLatin1String("--dump-tree"));
     if (dumpTree) {
         printf("\n\n");
         QSGNodeDumper::dump(rootNode());
     }
-#endif
 
 #ifdef RENDERER_DEBUG
     debugTimer.invalidate();
index 25f8f34..a4a47de 100644 (file)
@@ -302,6 +302,11 @@ void QSGNode::init()
         }
     }
 #endif
+
+#ifdef QSG_RUNTIME_DESCRIPTION
+    if (d_ptr.isNull())
+        d_ptr.reset(new QSGNodePrivate());
+#endif
 }
 
 /*!
@@ -671,7 +676,12 @@ void QSGNode::markDirty(DirtyState bits)
     }
 }
 
-
+#ifdef QSG_RUNTIME_DESCRIPTION
+void qsgnode_set_description(QSGNode *node, const QString &description)
+{
+    QSGNodePrivate::setDescription(node, description);
+}
+#endif
 
 /*!
     \class QSGBasicGeometryNode
@@ -1422,10 +1432,10 @@ void QSGNodeVisitor::visitChildren(QSGNode *n)
 QDebug operator<<(QDebug d, const QSGGeometryNode *n)
 {
     if (!n) {
-        d << "QSGGeometryNode(null)";
+        d << "Geometry(null)";
         return d;
     }
-    d << "QSGGeometryNode(" << hex << (void *) n << dec;
+    d << "GeometryNode(" << hex << (void *) n << dec;
 
     const QSGGeometry *g = n->geometry();
 
@@ -1440,33 +1450,32 @@ QDebug operator<<(QDebug d, const QSGGeometryNode *n)
         default: break;
         }
 
-         d << g->vertexCount();
+        d << "#V:" << g->vertexCount() << "#I:" << g->indexCount();
 
-         if (g->attributeCount() > 0 && g->attributes()->type == GL_FLOAT) {
-             float x1 = 1e10, x2 = -1e10, y1=1e10, y2=-1e10;
-             int stride = g->sizeOfVertex();
-             for (int i = 0; i < g->vertexCount(); ++i) {
-                 float x = ((float *)((char *)const_cast<QSGGeometry *>(g)->vertexData() + i * stride))[0];
-                 float y = ((float *)((char *)const_cast<QSGGeometry *>(g)->vertexData() + i * stride))[1];
+        if (g->attributeCount() > 0 && g->attributes()->type == GL_FLOAT) {
+            float x1 = 1e10, x2 = -1e10, y1=1e10, y2=-1e10;
+            int stride = g->sizeOfVertex();
+            for (int i = 0; i < g->vertexCount(); ++i) {
+                float x = ((float *)((char *)const_cast<QSGGeometry *>(g)->vertexData() + i * stride))[0];
+                float y = ((float *)((char *)const_cast<QSGGeometry *>(g)->vertexData() + i * stride))[1];
 
-                 x1 = qMin(x1, x);
-                 x2 = qMax(x2, x);
-                 y1 = qMin(y1, y);
-                 y2 = qMax(y2, y);
-             }
+                x1 = qMin(x1, x);
+                x2 = qMax(x2, x);
+                y1 = qMin(y1, y);
+                y2 = qMax(y2, y);
+            }
 
-             d << "x1=" << x1 << "y1=" << y1 << "x2=" << x2 << "y2=" << y2;
-         }
+            d << "x1=" << x1 << "y1=" << y1 << "x2=" << x2 << "y2=" << y2;
+        }
     }
 
-    d << "order=" << n->renderOrder();
     if (n->material())
-        d << "effect=" << n->material() << "type=" << n->material()->type();
+        d << "materialtype=" << n->material()->type();
 
 
     d << ')';
-#ifdef QML_RUNTIME_TESTING
-    d << n->description;
+#ifdef QSG_RUNTIME_DESCRIPTION
+    d << QSGNodePrivate::description(n);
 #endif
     d << "dirty=" << hex << (int) n->dirtyState() << dec;
     return d;
@@ -1475,10 +1484,10 @@ QDebug operator<<(QDebug d, const QSGGeometryNode *n)
 QDebug operator<<(QDebug d, const QSGClipNode *n)
 {
     if (!n) {
-        d << "QSGClipNode(null)";
+        d << "ClipNode(null)";
         return d;
     }
-    d << "QSGClipNode(" << hex << (void *) n << dec;
+    d << "ClipNode(" << hex << (void *) n << dec;
 
     if (n->childCount())
         d << "children=" << n->childCount();
@@ -1486,8 +1495,8 @@ QDebug operator<<(QDebug d, const QSGClipNode *n)
     d << "is rect?" << (n->isRectangular() ? "yes" : "no");
 
     d << ')';
-#ifdef QML_RUNTIME_TESTING
-    d << n->description;
+#ifdef QSG_RUNTIME_DESCRIPTION
+    d << QSGNodePrivate::description(n);
 #endif
     d << "dirty=" << hex << (int) n->dirtyState() << dec << (n->isSubtreeBlocked() ? "*BLOCKED*" : "");
     return d;
@@ -1496,11 +1505,11 @@ QDebug operator<<(QDebug d, const QSGClipNode *n)
 QDebug operator<<(QDebug d, const QSGTransformNode *n)
 {
     if (!n) {
-        d << "QSGTransformNode(null)";
+        d << "TransformNode(null)";
         return d;
     }
     const QMatrix4x4 m = n->matrix();
-    d << "QSGTransformNode(";
+    d << "TransformNode(";
     d << hex << (void *) n << dec;
     if (m.isIdentity())
         d << "identity";
@@ -1508,8 +1517,8 @@ QDebug operator<<(QDebug d, const QSGTransformNode *n)
         d << "translate" << m(0, 3) << m(1, 3) << m(2, 3);
     else
         d << "det=" << n->matrix().determinant();
-#ifdef QML_RUNTIME_TESTING
-    d << n->description;
+#ifdef QSG_RUNTIME_DESCRIPTION
+    d << QSGNodePrivate::description(n);
 #endif
     d << "dirty=" << hex << (int) n->dirtyState() << dec << (n->isSubtreeBlocked() ? "*BLOCKED*" : "");
     d << ')';
@@ -1519,16 +1528,16 @@ QDebug operator<<(QDebug d, const QSGTransformNode *n)
 QDebug operator<<(QDebug d, const QSGOpacityNode *n)
 {
     if (!n) {
-        d << "QSGOpacityNode(null)";
+        d << "OpacityNode(null)";
         return d;
     }
-    d << "QSGOpacityNode(";
+    d << "OpacityNode(";
     d << hex << (void *) n << dec;
     d << "opacity=" << n->opacity()
       << "combined=" << n->combinedOpacity()
       << (n->isSubtreeBlocked() ? "*BLOCKED*" : "");
-#ifdef QML_RUNTIME_TESTING
-    d << n->description;
+#ifdef QSG_RUNTIME_DESCRIPTION
+    d << QSGNodePrivate::description(n);
 #endif
     d << "dirty=" << hex << (int) n->dirtyState() << dec;
     d << ')';
@@ -1539,13 +1548,13 @@ QDebug operator<<(QDebug d, const QSGOpacityNode *n)
 QDebug operator<<(QDebug d, const QSGRootNode *n)
 {
     if (!n) {
-        d << "QSGRootNode(null)";
+        d << "RootNode(null)";
         return d;
     }
-    d << "QSGRootNode" << hex << (void *) n << "dirty=" << (int) n->dirtyState() << dec
+    d << "RootNode" << hex << (void *) n << "dirty=" << (int) n->dirtyState() << dec
       << (n->isSubtreeBlocked() ? "*BLOCKED*" : "");
-#ifdef QML_RUNTIME_TESTING
-    d << n->description;
+#ifdef QSG_RUNTIME_DESCRIPTION
+    d << QSGNodePrivate::description(n);
 #endif
     d << ')';
     return d;
@@ -1556,7 +1565,7 @@ QDebug operator<<(QDebug d, const QSGRootNode *n)
 QDebug operator<<(QDebug d, const QSGNode *n)
 {
     if (!n) {
-        d << "QSGNode(null)";
+        d << "Node(null)";
         return d;
     }
     switch (n->type()) {
@@ -1576,12 +1585,12 @@ QDebug operator<<(QDebug d, const QSGNode *n)
         d << static_cast<const QSGOpacityNode *>(n);
         break;
     default:
-        d << "QSGNode(" << hex << (void *) n << dec
+        d << "Node(" << hex << (void *) n << dec
           << "dirty=" << hex << (int) n->dirtyState()
           << "flags=" << (int) n->flags() << dec
           << (n->isSubtreeBlocked() ? "*BLOCKED*" : "");
-#ifdef QML_RUNTIME_TESTING
-        d << n->description;
+#ifdef QSG_RUNTIME_DESCRIPTION
+        d << QSGNodePrivate::description(n);
 #endif
         d << ')';
         break;
index d83e6bc..26af56f 100644 (file)
@@ -49,7 +49,7 @@
 
 QT_BEGIN_NAMESPACE
 
-//#define QML_RUNTIME_TESTING
+// #define QSG_RUNTIME_DESCRIPTION
 
 class QSGRenderer;
 
@@ -146,10 +146,6 @@ public:
 
     virtual void preprocess() { }
 
-#ifdef QML_RUNTIME_TESTING
-    QString description;
-#endif
-
 protected:
     QSGNode(NodeType type);
     QSGNode(QSGNodePrivate &dd, NodeType type);
@@ -172,9 +168,15 @@ private:
     DirtyState m_dirtyState;
 
 protected:
+    friend class QSGNodePrivate;
+
     QScopedPointer<QSGNodePrivate> d_ptr;
 };
 
+#ifdef QSG_RUNTIME_DESCRIPTION
+void qsgnode_set_description(QSGNode *node, const QString &description);
+#endif
+
 class Q_QUICK_EXPORT QSGBasicGeometryNode : public QSGNode
 {
 public:
index b0d8088..0b9bc67 100644 (file)
@@ -44,6 +44,8 @@
 
 #include <qglobal.h>
 
+#include "qsgnode.h"
+
 QT_BEGIN_NAMESPACE
 
 class QSGNodePrivate
@@ -51,6 +53,16 @@ class QSGNodePrivate
 public:
     QSGNodePrivate() {}
     virtual ~QSGNodePrivate() {}
+
+#ifdef QSG_RUNTIME_DESCRIPTION
+    static void setDescription(QSGNode *node, const QString &description) {
+        node->d_ptr->descr= description;
+    }
+    static QString description(const QSGNode *node) {
+        return node->d_ptr->descr;
+    }
+    QString descr;
+#endif
 };
 
 
index 805cfaa..8412af1 100644 (file)
@@ -762,7 +762,7 @@ void QSGNodeDumper::dump(QSGNode *n)
 
 void QSGNodeDumper::visitNode(QSGNode *n)
 {
-    qDebug() << QString(m_indent * 2, QLatin1Char(' ')) << n;
+    qDebug() << QByteArray(m_indent * 2, ' ').constData() << n;
     QSGNodeVisitor::visitNode(n);
 }
 
index 8f24485..e696e92 100644 (file)
@@ -78,8 +78,8 @@ void QSGDefaultGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &gl
     m_position = position;
     m_glyphs = glyphs;
 
-#ifdef QML_RUNTIME_TESTING
-    description = QLatin1String("glyphs");
+#ifdef QSG_RUNTIME_DESCRIPTION
+    qsgnode_set_description(this, QLatin1String("glyphs"));
 #endif
 }
 
index aed6991..c53039c 100644 (file)
@@ -213,8 +213,8 @@ QSGDefaultImageNode::QSGDefaultImageNode()
     setOpaqueMaterial(&m_material);
     setGeometry(&m_geometry);
 
-#ifdef QML_RUNTIME_TESTING
-    description = QLatin1String("image");
+#ifdef QSG_RUNTIME_DESCRIPTION
+    qsgnode_set_description(this, QLatin1String("image"));
 #endif
 }
 
index 276041d..ab8b2e7 100644 (file)
@@ -246,8 +246,8 @@ QSGDefaultRectangleNode::QSGDefaultRectangleNode()
     setGeometry(&m_geometry);
     setMaterial(&m_material);
 
-#ifdef QML_RUNTIME_TESTING
-    description = QLatin1String("rectangle");
+#ifdef QSG_RUNTIME_DESCRIPTION
+    qsgnode_set_description(this, QLatin1String("rectangle"));
 #endif
 }
 
index 1b10b8b..1d36abe 100644 (file)
@@ -61,8 +61,8 @@ QSGDistanceFieldGlyphNode::QSGDistanceFieldGlyphNode(QSGContext *context)
     m_geometry.setDrawingMode(GL_TRIANGLES);
     setGeometry(&m_geometry);
     setFlag(UsePreprocess);
-#ifdef QML_RUNTIME_TESTING
-    description = QLatin1String("glyphs");
+#ifdef QSG_RUNTIME_DESCRIPTION
+    qsgnode_set_description(this, QLatin1String("glyphs"));
 #endif
 }
 
index 86e0d36..e5b351e 100644 (file)
@@ -103,6 +103,9 @@ QSGSimpleTextureNode::QSGSimpleTextureNode()
     setGeometry(&m_geometry);
     setMaterial(&m_material);
     setOpaqueMaterial(&m_opaque_material);
+#ifdef QSG_RUNTIME_DESCRIPTION
+    qsgnode_set_description(this, QLatin1String("simpletexture"));
+#endif
 }
 
 /*!