From 57a70efe4c54bbfc8109933503c45cc43127c6ad Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 2 Aug 2013 21:04:44 +0200 Subject: Support opt-in QSGNode descriptions without breaking binary compat. 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 --- .../scenegraph/coreapi/qsgdefaultrenderer.cpp | 2 - src/quick/scenegraph/coreapi/qsgnode.cpp | 91 ++++++++++++---------- src/quick/scenegraph/coreapi/qsgnode.h | 12 +-- src/quick/scenegraph/coreapi/qsgnode_p.h | 12 +++ src/quick/scenegraph/coreapi/qsgrenderer.cpp | 2 +- 5 files changed, 70 insertions(+), 49 deletions(-) (limited to 'src/quick/scenegraph/coreapi') diff --git a/src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp b/src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp index 448ec55a82..a343a81e1a 100644 --- a/src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp @@ -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(); diff --git a/src/quick/scenegraph/coreapi/qsgnode.cpp b/src/quick/scenegraph/coreapi/qsgnode.cpp index 25f8f342c9..a4a47de216 100644 --- a/src/quick/scenegraph/coreapi/qsgnode.cpp +++ b/src/quick/scenegraph/coreapi/qsgnode.cpp @@ -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(g)->vertexData() + i * stride))[0]; - float y = ((float *)((char *)const_cast(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(g)->vertexData() + i * stride))[0]; + float y = ((float *)((char *)const_cast(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(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; diff --git a/src/quick/scenegraph/coreapi/qsgnode.h b/src/quick/scenegraph/coreapi/qsgnode.h index d83e6bcc81..26af56f3d0 100644 --- a/src/quick/scenegraph/coreapi/qsgnode.h +++ b/src/quick/scenegraph/coreapi/qsgnode.h @@ -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 d_ptr; }; +#ifdef QSG_RUNTIME_DESCRIPTION +void qsgnode_set_description(QSGNode *node, const QString &description); +#endif + class Q_QUICK_EXPORT QSGBasicGeometryNode : public QSGNode { public: diff --git a/src/quick/scenegraph/coreapi/qsgnode_p.h b/src/quick/scenegraph/coreapi/qsgnode_p.h index b0d8088af2..0b9bc67d1e 100644 --- a/src/quick/scenegraph/coreapi/qsgnode_p.h +++ b/src/quick/scenegraph/coreapi/qsgnode_p.h @@ -44,6 +44,8 @@ #include +#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 }; diff --git a/src/quick/scenegraph/coreapi/qsgrenderer.cpp b/src/quick/scenegraph/coreapi/qsgrenderer.cpp index 805cfaad0d..8412af13d9 100644 --- a/src/quick/scenegraph/coreapi/qsgrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgrenderer.cpp @@ -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); } -- cgit v1.2.3