diff --git a/src/quick/items/qquickpainteditem.cpp b/src/quick/items/qquickpainteditem.cpp index 08145d89aa5b1ee7c917aa8e19a5143d7be90c1a..bc148c5bca62ff8128acda8db38e03ec0a1df5a3 100644 --- a/src/quick/items/qquickpainteditem.cpp +++ b/src/quick/items/qquickpainteditem.cpp @@ -34,7 +34,7 @@ #include "qquickpainteditem.h" #include <private/qquickpainteditem_p.h> -#include <QtQuick/private/qsgpainternode_p.h> +#include <QtQuick/private/qsgdefaultpainternode_p.h> #include <QtQuick/private/qsgcontext_p.h> #include <private/qsgadaptationlayer_p.h> @@ -523,7 +523,7 @@ QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat QSGPainterNode *node = static_cast<QSGPainterNode *>(oldNode); if (!node) { - node = new QSGPainterNode(this); + node = d->sceneGraphContext()->createPainterNode(this); d->node = node; } diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h index 33ee180864bf244a130d4901dc567c3aa057560c..c96d0a99e3c0aa6099e3a5fbdc66766bb2f3be87 100644 --- a/src/quick/scenegraph/qsgadaptationlayer_p.h +++ b/src/quick/scenegraph/qsgadaptationlayer_p.h @@ -60,6 +60,7 @@ class QSGDistanceFieldGlyphCacheManager; class QSGDistanceFieldGlyphNode; class QOpenGLContext; class QSGImageNode; +class QSGPainterNode; class QSGRectangleNode; class QSGGlyphNode; class QSGNinePatchNode; @@ -81,6 +82,8 @@ public: virtual void endVisit(QSGOpacityNode *) = 0; virtual bool visit(QSGImageNode *) = 0; virtual void endVisit(QSGImageNode *) = 0; + virtual bool visit(QSGPainterNode *) = 0; + virtual void endVisit(QSGPainterNode *) = 0; virtual bool visit(QSGRectangleNode *) = 0; virtual void endVisit(QSGRectangleNode *) = 0; virtual bool visit(QSGGlyphNode *) = 0; @@ -143,6 +146,28 @@ public: virtual void accept(QSGNodeVisitorEx *visitor) { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); } }; +class Q_QUICK_PRIVATE_EXPORT QSGPainterNode : public QSGVisitableNode +{ +public: + + virtual void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) = 0; + virtual void setSize(const QSize &size) = 0; + virtual void setDirty(const QRect &dirtyRect = QRect()) = 0; + virtual void setOpaquePainting(bool opaque) = 0; + virtual void setLinearFiltering(bool linearFiltering) = 0; + virtual void setMipmapping(bool mipmapping) = 0; + virtual void setSmoothPainting(bool s) = 0; + virtual void setFillColor(const QColor &c) = 0; + virtual void setContentsScale(qreal s) = 0; + virtual void setFastFBOResizing(bool dynamic) = 0; + + virtual QImage toImage() const = 0; + virtual void update() = 0; + virtual QSGTexture *texture() const = 0; + + virtual void accept(QSGNodeVisitorEx *visitor) { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); } +}; + class Q_QUICK_PRIVATE_EXPORT QSGNinePatchNode : public QSGVisitableNode { public: diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp index 1a3eea86bbb51ba448c7f9dbbf149b0f13a72eda..0bca81d48c7ec5db15104589df6fed81d4d2fda2 100644 --- a/src/quick/scenegraph/qsgcontext.cpp +++ b/src/quick/scenegraph/qsgcontext.cpp @@ -37,6 +37,7 @@ #include <QtQuick/private/qsgdefaultdistancefieldglyphcache_p.h> #include <QtQuick/private/qsgdefaultrectanglenode_p.h> #include <QtQuick/private/qsgdefaultimagenode_p.h> +#include <QtQuick/private/qsgdefaultpainternode_p.h> #include <QtQuick/private/qsgdefaultglyphnode_p.h> #include <QtQuick/private/qsgdistancefieldglyphnode_p.h> #include <QtQuick/private/qsgdistancefieldglyphnode_p_p.h> @@ -290,6 +291,14 @@ QSGImageNode *QSGContext::createImageNode() : new QSGDefaultImageNode; } +/*! + Factory function for scene graph backends of Painter elements + */ +QSGPainterNode *QSGContext::createPainterNode(QQuickPaintedItem *item) +{ + return new QSGDefaultPainterNode(item); +} + /*! Factory function for scene graph backends of the Text elements; */ diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h index 12b26b47be1a505ec5b66ab24421437fc16f221e..184b8248d554a8f19f8f1163d6c2eedda2de627e 100644 --- a/src/quick/scenegraph/qsgcontext_p.h +++ b/src/quick/scenegraph/qsgcontext_p.h @@ -55,6 +55,7 @@ namespace QSGAtlasTexture { class QSGContextPrivate; class QSGRectangleNode; class QSGImageNode; +class QSGPainterNode; class QSGGlyphNode; class QSGNinePatchNode; class QSGRenderer; @@ -72,6 +73,7 @@ class QOpenGLFramebufferObject; class QQuickTextureFactory; class QSGDistanceFieldGlyphCacheManager; class QSGContext; +class QQuickPaintedItem; Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERLOOP) Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_COMPILATION) @@ -169,6 +171,7 @@ public: QSGRectangleNode *createRectangleNode(const QRectF &rect, const QColor &c); virtual QSGRectangleNode *createRectangleNode(); virtual QSGImageNode *createImageNode(); + virtual QSGPainterNode *createPainterNode(QQuickPaintedItem *item); virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode); virtual QSGNinePatchNode *createNinePatchNode(); virtual QSGLayer *createLayer(QSGRenderContext *renderContext); diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri index 4d9d7444b374524409031e063f323a27bbc358bd..bcb523f90d3ac0a2c2c102a06be7e8f5c7840377 100644 --- a/src/quick/scenegraph/scenegraph.pri +++ b/src/quick/scenegraph/scenegraph.pri @@ -45,7 +45,7 @@ HEADERS += \ $$PWD/util/qsgtexture.h \ $$PWD/util/qsgtexture_p.h \ $$PWD/util/qsgtextureprovider.h \ - $$PWD/util/qsgpainternode_p.h \ + $$PWD/util/qsgdefaultpainternode_p.h \ $$PWD/util/qsgdistancefieldutil_p.h \ $$PWD/util/qsgshadersourcebuilder_p.h @@ -61,7 +61,7 @@ SOURCES += \ $$PWD/util/qsgvertexcolormaterial.cpp \ $$PWD/util/qsgtexture.cpp \ $$PWD/util/qsgtextureprovider.cpp \ - $$PWD/util/qsgpainternode.cpp \ + $$PWD/util/qsgdefaultpainternode.cpp \ $$PWD/util/qsgdistancefieldutil.cpp \ $$PWD/util/qsgsimplematerial.cpp \ $$PWD/util/qsgshadersourcebuilder.cpp diff --git a/src/quick/scenegraph/util/qsgpainternode.cpp b/src/quick/scenegraph/util/qsgdefaultpainternode.cpp similarity index 91% rename from src/quick/scenegraph/util/qsgpainternode.cpp rename to src/quick/scenegraph/util/qsgdefaultpainternode.cpp index a74cf869a49cbc848e30010441be3d5a8bb455e5..6135d958d501df3cabd1673c0b4483103c6a7582 100644 --- a/src/quick/scenegraph/util/qsgpainternode.cpp +++ b/src/quick/scenegraph/util/qsgdefaultpainternode.cpp @@ -31,7 +31,7 @@ ** ****************************************************************************/ -#include "qsgpainternode_p.h" +#include "qsgdefaultpainternode_p.h" #include <QtQuick/private/qquickpainteditem_p.h> @@ -66,8 +66,8 @@ void QSGPainterTexture::bind() m_dirty_rect = QRect(); } -QSGPainterNode::QSGPainterNode(QQuickPaintedItem *item) - : QSGGeometryNode() +QSGDefaultPainterNode::QSGDefaultPainterNode(QQuickPaintedItem *item) + : QSGPainterNode() , m_preferredRenderTarget(QQuickPaintedItem::Image) , m_actualRenderTarget(QQuickPaintedItem::Image) , m_item(item) @@ -101,7 +101,7 @@ QSGPainterNode::QSGPainterNode(QQuickPaintedItem *item) #endif } -QSGPainterNode::~QSGPainterNode() +QSGDefaultPainterNode::~QSGDefaultPainterNode() { delete m_texture; delete m_fbo; @@ -109,7 +109,7 @@ QSGPainterNode::~QSGPainterNode() delete m_gl_device; } -void QSGPainterNode::paint() +void QSGDefaultPainterNode::paint() { QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect; @@ -168,7 +168,7 @@ void QSGPainterNode::paint() m_dirtyRect = QRect(); } -void QSGPainterNode::update() +void QSGDefaultPainterNode::update() { if (m_dirtyRenderTarget) updateRenderTarget(); @@ -186,7 +186,7 @@ void QSGPainterNode::update() m_dirtyContents = false; } -void QSGPainterNode::updateTexture() +void QSGDefaultPainterNode::updateTexture() { m_texture->setHasAlphaChannel(!m_opaquePainting); m_material.setTexture(m_texture); @@ -195,7 +195,7 @@ void QSGPainterNode::updateTexture() markDirty(DirtyMaterial); } -void QSGPainterNode::updateGeometry() +void QSGDefaultPainterNode::updateGeometry() { QRectF source; if (m_actualRenderTarget == QQuickPaintedItem::Image) @@ -211,7 +211,7 @@ void QSGPainterNode::updateGeometry() markDirty(DirtyGeometry); } -void QSGPainterNode::updateRenderTarget() +void QSGDefaultPainterNode::updateRenderTarget() { if (!m_extensionsChecked) { const QSet<QByteArray> extensions = m_context->openglContext()->extensions(); @@ -297,7 +297,7 @@ void QSGPainterNode::updateRenderTarget() m_texture = texture; } -void QSGPainterNode::updateFBOSize() +void QSGDefaultPainterNode::updateFBOSize() { int fboWidth; int fboHeight; @@ -313,7 +313,7 @@ void QSGPainterNode::updateFBOSize() m_fboSize = QSize(fboWidth, fboHeight); } -void QSGPainterNode::setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) +void QSGDefaultPainterNode::setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) { if (m_preferredRenderTarget == target) return; @@ -325,7 +325,7 @@ void QSGPainterNode::setPreferredRenderTarget(QQuickPaintedItem::RenderTarget ta m_dirtyTexture = true; } -void QSGPainterNode::setSize(const QSize &size) +void QSGDefaultPainterNode::setSize(const QSize &size) { if (size == m_size) return; @@ -341,7 +341,7 @@ void QSGPainterNode::setSize(const QSize &size) m_dirtyTexture = true; } -void QSGPainterNode::setDirty(const QRect &dirtyRect) +void QSGDefaultPainterNode::setDirty(const QRect &dirtyRect) { m_dirtyContents = true; m_dirtyRect = dirtyRect; @@ -352,7 +352,7 @@ void QSGPainterNode::setDirty(const QRect &dirtyRect) markDirty(DirtyMaterial); } -void QSGPainterNode::setOpaquePainting(bool opaque) +void QSGDefaultPainterNode::setOpaquePainting(bool opaque) { if (opaque == m_opaquePainting) return; @@ -361,7 +361,7 @@ void QSGPainterNode::setOpaquePainting(bool opaque) m_dirtyTexture = true; } -void QSGPainterNode::setLinearFiltering(bool linearFiltering) +void QSGDefaultPainterNode::setLinearFiltering(bool linearFiltering) { if (linearFiltering == m_linear_filtering) return; @@ -373,7 +373,7 @@ void QSGPainterNode::setLinearFiltering(bool linearFiltering) markDirty(DirtyMaterial); } -void QSGPainterNode::setMipmapping(bool mipmapping) +void QSGDefaultPainterNode::setMipmapping(bool mipmapping) { if (mipmapping == m_mipmapping) return; @@ -384,7 +384,7 @@ void QSGPainterNode::setMipmapping(bool mipmapping) m_dirtyTexture = true; } -void QSGPainterNode::setSmoothPainting(bool s) +void QSGDefaultPainterNode::setSmoothPainting(bool s) { if (s == m_smoothPainting) return; @@ -393,7 +393,7 @@ void QSGPainterNode::setSmoothPainting(bool s) m_dirtyRenderTarget = true; } -void QSGPainterNode::setFillColor(const QColor &c) +void QSGDefaultPainterNode::setFillColor(const QColor &c) { if (c == m_fillColor) return; @@ -402,7 +402,7 @@ void QSGPainterNode::setFillColor(const QColor &c) markDirty(DirtyMaterial); } -void QSGPainterNode::setContentsScale(qreal s) +void QSGDefaultPainterNode::setContentsScale(qreal s) { if (s == m_contentsScale) return; @@ -411,12 +411,12 @@ void QSGPainterNode::setContentsScale(qreal s) markDirty(DirtyMaterial); } -void QSGPainterNode::setFastFBOResizing(bool dynamic) +void QSGDefaultPainterNode::setFastFBOResizing(bool dynamic) { m_fastFBOResizing = dynamic; } -QImage QSGPainterNode::toImage() const +QImage QSGDefaultPainterNode::toImage() const { if (m_actualRenderTarget == QQuickPaintedItem::Image) return m_image; diff --git a/src/quick/scenegraph/util/qsgpainternode_p.h b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h similarity index 92% rename from src/quick/scenegraph/util/qsgpainternode_p.h rename to src/quick/scenegraph/util/qsgdefaultpainternode_p.h index 15ba2625f0444e5e9f3713314f4f393da81e0fb1..a87aeb5b4409e055acc54c3d3b6f74320f7b907f 100644 --- a/src/quick/scenegraph/util/qsgpainternode_p.h +++ b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h @@ -31,10 +31,10 @@ ** ****************************************************************************/ -#ifndef QSGPAINTERNODE_P_H -#define QSGPAINTERNODE_P_H +#ifndef QSGDEFAULTPAINTERNODE_P_H +#define QSGDEFAULTPAINTERNODE_P_H -#include <QtQuick/qsgnode.h> +#include <private/qsgadaptationlayer_p.h> #include "qsgtexturematerial.h" #include "qsgtexture_p.h" @@ -60,11 +60,11 @@ private: QRect m_dirty_rect; }; -class Q_QUICK_PRIVATE_EXPORT QSGPainterNode : public QSGGeometryNode +class Q_QUICK_PRIVATE_EXPORT QSGDefaultPainterNode : public QSGPainterNode { public: - QSGPainterNode(QQuickPaintedItem *item); - virtual ~QSGPainterNode(); + QSGDefaultPainterNode(QQuickPaintedItem *item); + virtual ~QSGDefaultPainterNode(); void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target); @@ -145,4 +145,4 @@ private: QT_END_NAMESPACE -#endif // QSGPAINTERNODE_P_H +#endif // QSGDEFAULTPAINTERNODE_P_H diff --git a/tests/auto/quick/nokeywords/tst_nokeywords.cpp b/tests/auto/quick/nokeywords/tst_nokeywords.cpp index 1884710c90b53990ff160d9b1d898f3a41e4c8cf..1a20649b2d4c46570f98cf01ba6ca2760e06940a 100644 --- a/tests/auto/quick/nokeywords/tst_nokeywords.cpp +++ b/tests/auto/quick/nokeywords/tst_nokeywords.cpp @@ -63,7 +63,7 @@ #include <QtQuick/private/qsggeometry_p.h> #include <QtQuick/private/qsgnode_p.h> #include <QtQuick/private/qsgnodeupdater_p.h> -#include <QtQuick/private/qsgpainternode_p.h> +#include <QtQuick/private/qsgdefaultpainternode_p.h> #include <QtQuick/private/qsgrenderer_p.h> #include <QtQuick/private/qsgrenderloop_p.h> #include <QtQuick/private/qsgrendernode_p.h> diff --git a/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp b/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp index d9e893692d64f5d4013cdf5f51ed33eb2f437c73..4ae880f95b1f8c883e2937fe3e4ecfd2338cd1ef 100644 --- a/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp +++ b/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp @@ -37,7 +37,7 @@ #include <QtQuick/qquickview.h> #include <private/qquickitem_p.h> -#include <private/qsgpainternode_p.h> +#include <private/qsgdefaultpainternode_p.h> class tst_QQuickPaintedItem: public QObject { @@ -78,11 +78,11 @@ public: QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) { - paintNode = static_cast<QSGPainterNode *>(QQuickPaintedItem::updatePaintNode(oldNode, data)); + paintNode = static_cast<QSGDefaultPainterNode *>(QQuickPaintedItem::updatePaintNode(oldNode, data)); return paintNode; } - QSGPainterNode *paintNode; + QSGDefaultPainterNode *paintNode; int paintRequests; QRectF clipRect; };