From: Gunnar Sletta Date: Fri, 2 Aug 2013 19:04:44 +0000 (+0200) Subject: Support opt-in QSGNode descriptions without breaking binary compat. X-Git-Tag: upstream/5.2.1~717 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57a70efe4c54bbfc8109933503c45cc43127c6ad;p=platform%2Fupstream%2Fqtdeclarative.git 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 --- diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h index 0ffc092..fe70b38 100644 --- a/src/quick/items/qquickitem_p.h +++ b/src/quick/items/qquickitem_p.h @@ -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; diff --git a/src/quick/items/qquickshadereffectnode.cpp b/src/quick/items/qquickshadereffectnode.cpp index 17c5e4c..d2a6184 100644 --- a/src/quick/items/qquickshadereffectnode.cpp +++ b/src/quick/items/qquickshadereffectnode.cpp @@ -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 } diff --git a/src/quick/items/qquicktextnode.cpp b/src/quick/items/qquicktextnode.cpp index d8040a1..d3a566f 100644 --- a/src/quick/items/qquicktextnode.cpp +++ b/src/quick/items/qquicktextnode.cpp @@ -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 } diff --git a/src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp b/src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp index 448ec55..a343a81 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 25f8f34..a4a47de 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 d83e6bc..26af56f 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 b0d8088..0b9bc67 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 805cfaa..8412af1 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); } diff --git a/src/quick/scenegraph/qsgdefaultglyphnode.cpp b/src/quick/scenegraph/qsgdefaultglyphnode.cpp index 8f24485..e696e92 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode.cpp @@ -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 } diff --git a/src/quick/scenegraph/qsgdefaultimagenode.cpp b/src/quick/scenegraph/qsgdefaultimagenode.cpp index aed6991..c53039c 100644 --- a/src/quick/scenegraph/qsgdefaultimagenode.cpp +++ b/src/quick/scenegraph/qsgdefaultimagenode.cpp @@ -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 } diff --git a/src/quick/scenegraph/qsgdefaultrectanglenode.cpp b/src/quick/scenegraph/qsgdefaultrectanglenode.cpp index 276041d..ab8b2e7 100644 --- a/src/quick/scenegraph/qsgdefaultrectanglenode.cpp +++ b/src/quick/scenegraph/qsgdefaultrectanglenode.cpp @@ -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 } diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode.cpp index 1b10b8b..1d36abe 100644 --- a/src/quick/scenegraph/qsgdistancefieldglyphnode.cpp +++ b/src/quick/scenegraph/qsgdistancefieldglyphnode.cpp @@ -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 } diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp index 86e0d36..e5b351e 100644 --- a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp +++ b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp @@ -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 } /*!