From: Andy Nichols Date: Tue, 19 Aug 2014 14:08:23 +0000 (+0200) Subject: Added QSGPainterNode abstraction to QSGAdaptationLayer X-Git-Tag: v5.3.99+beta1~112 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ae3e24e339b6f9b1f4f3bcf66d76b8f045932e7;p=platform%2Fupstream%2Fqtdeclarative.git Added QSGPainterNode abstraction to QSGAdaptationLayer This allows the scenegraph backend to customize how QSGPainterNodes are rendered. Change-Id: I640dcf121d0be6bda615cf30591d502329fc89d0 Reviewed-by: Lars Knoll Reviewed-by: Gunnar Sletta --- diff --git a/src/quick/items/qquickpainteditem.cpp b/src/quick/items/qquickpainteditem.cpp index 08145d8..bc148c5 100644 --- a/src/quick/items/qquickpainteditem.cpp +++ b/src/quick/items/qquickpainteditem.cpp @@ -34,7 +34,7 @@ #include "qquickpainteditem.h" #include -#include +#include #include #include @@ -523,7 +523,7 @@ QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat QSGPainterNode *node = static_cast(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 33ee180..c96d0a9 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 1a3eea8..0bca81d 100644 --- a/src/quick/scenegraph/qsgcontext.cpp +++ b/src/quick/scenegraph/qsgcontext.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -291,6 +292,14 @@ QSGImageNode *QSGContext::createImageNode() } /*! + 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; */ QSGGlyphNode *QSGContext::createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h index 12b26b4..184b824 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 4d9d744..bcb523f 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 a74cf86..6135d95 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 @@ -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 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 15ba262..a87aeb5 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 +#include #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 1884710..1a20649 100644 --- a/tests/auto/quick/nokeywords/tst_nokeywords.cpp +++ b/tests/auto/quick/nokeywords/tst_nokeywords.cpp @@ -63,7 +63,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp b/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp index d9e8936..4ae880f 100644 --- a/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp +++ b/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include class tst_QQuickPaintedItem: public QObject { @@ -78,11 +78,11 @@ public: QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) { - paintNode = static_cast(QQuickPaintedItem::updatePaintNode(oldNode, data)); + paintNode = static_cast(QQuickPaintedItem::updatePaintNode(oldNode, data)); return paintNode; } - QSGPainterNode *paintNode; + QSGDefaultPainterNode *paintNode; int paintRequests; QRectF clipRect; };