Added QSGPainterNode abstraction to QSGAdaptationLayer
authorAndy Nichols <andy.nichols@digia.com>
Tue, 19 Aug 2014 14:08:23 +0000 (16:08 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 27 Aug 2014 06:13:46 +0000 (08:13 +0200)
This allows the scenegraph backend to customize how QSGPainterNodes are
rendered.

Change-Id: I640dcf121d0be6bda615cf30591d502329fc89d0
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
src/quick/items/qquickpainteditem.cpp
src/quick/scenegraph/qsgadaptationlayer_p.h
src/quick/scenegraph/qsgcontext.cpp
src/quick/scenegraph/qsgcontext_p.h
src/quick/scenegraph/scenegraph.pri
src/quick/scenegraph/util/qsgdefaultpainternode.cpp [moved from src/quick/scenegraph/util/qsgpainternode.cpp with 91% similarity]
src/quick/scenegraph/util/qsgdefaultpainternode_p.h [moved from src/quick/scenegraph/util/qsgpainternode_p.h with 92% similarity]
tests/auto/quick/nokeywords/tst_nokeywords.cpp
tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp

index 08145d8..bc148c5 100644 (file)
@@ -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;
     }
 
index 33ee180..c96d0a9 100644 (file)
@@ -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:
index 1a3eea8..0bca81d 100644 (file)
@@ -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>
@@ -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)
index 12b26b4..184b824 100644 (file)
@@ -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);
index 4d9d744..bcb523f 100644 (file)
@@ -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
@@ -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;
 **
 ****************************************************************************/
 
-#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
index 1884710..1a20649 100644 (file)
@@ -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>
index d9e8936..4ae880f 100644 (file)
@@ -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;
 };