aboutsummaryrefslogtreecommitdiffstats
path: root/softwarecontext
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-08-08 12:10:11 +0200
committerLars Knoll <lars.knoll@digia.com>2014-08-08 15:57:43 +0300
commit5fd71e9bd83935c907eb5ad8ffc270ae42ff05ae (patch)
tree157c16eb86aebc381584c2849e97ed99ec0d5807 /softwarecontext
parentd6ceb224da997b9afad3d899a6af62c54e5a443f (diff)
Adapt to new visitor pattern for rendering
Change-Id: I32b5d748a5cadcb88511f401924d3b3635275881 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'softwarecontext')
-rw-r--r--softwarecontext/context.cpp34
-rw-r--r--softwarecontext/context.h3
-rw-r--r--softwarecontext/glyphnode.h2
-rw-r--r--softwarecontext/imagenode.h2
-rw-r--r--softwarecontext/rectanglenode.h2
-rw-r--r--softwarecontext/renderingvisitor.cpp81
-rw-r--r--softwarecontext/renderingvisitor.h30
-rw-r--r--softwarecontext/softwarecontext.pro6
8 files changed, 121 insertions, 39 deletions
diff --git a/softwarecontext/context.cpp b/softwarecontext/context.cpp
index 9d0b7a3097..d656125f0c 100644
--- a/softwarecontext/context.cpp
+++ b/softwarecontext/context.cpp
@@ -45,6 +45,7 @@
#include "imagenode.h"
#include "pixmaptexture.h"
#include "glyphnode.h"
+#include "renderingvisitor.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QElapsedTimer>
@@ -99,42 +100,12 @@ void Renderer::render()
painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(rect, Qt::white);
- renderNode(&painter, rootNode());
+ RenderingVisitor(&painter).visitChildren(rootNode());
backingStore->endPaint();
backingStore->flush(rect);
}
-void Renderer::renderNode(QPainter *painter, QSGNode *node)
-{
- bool restore = false;
-
- if (node->type() == QSGNode::TransformNodeType) {
- QSGTransformNode *tn = static_cast<QSGTransformNode*>(node);
- painter->save();
- restore = true;
- painter->setTransform(tn->matrix().toTransform(), /*combine*/true);
- } else if (node->type() == QSGNode::ClipNodeType) {
- QSGClipNode *cn = static_cast<QSGClipNode*>(node);
- painter->save();
- restore = true;
- painter->setClipRect(cn->clipRect(), Qt::IntersectClip);
- } else if (node->type() == QSGNode::OpacityNodeType) {
- QSGOpacityNode *on = static_cast<QSGOpacityNode*>(node);
- painter->save();
- restore = true;
- painter->setOpacity(on->opacity());
- }
-
- node->paint(painter);
-
- for (QSGNode *child = node->firstChild(); child; child = child->nextSibling())
- renderNode(painter, child);
-
- if (restore)
- painter->restore();
-}
-
RenderContext::RenderContext(QSGContext *ctx)
: QSGRenderContext(ctx)
, currentWindow(0)
@@ -192,5 +163,4 @@ void RenderContext::renderNextFrame(QSGRenderer *renderer, GLuint fbo)
QSGRenderContext::renderNextFrame(renderer, fbo);
}
-
} // namespace
diff --git a/softwarecontext/context.h b/softwarecontext/context.h
index 0eb51ba9cd..b2d478d70a 100644
--- a/softwarecontext/context.h
+++ b/softwarecontext/context.h
@@ -45,6 +45,7 @@
#include <private/qsgcontext_p.h>
#include <private/qsgrenderer_p.h>
+#include <private/qsgadaptationlayer_p.h>
#include <QtCore/QElapsedTimer>
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/QBackingStore>
@@ -62,8 +63,6 @@ public:
virtual void render();
private:
- void renderNode(QPainter *painter, QSGNode *node);
-
QScopedPointer<QBackingStore> backingStore;
};
diff --git a/softwarecontext/glyphnode.h b/softwarecontext/glyphnode.h
index 1724ef8394..08d4d18895 100644
--- a/softwarecontext/glyphnode.h
+++ b/softwarecontext/glyphnode.h
@@ -16,7 +16,7 @@ public:
virtual void setPreferredAntialiasingMode(AntialiasingMode);
virtual void update();
- virtual void paint(QPainter *painter);
+ void paint(QPainter *painter);
private:
QPointF m_position;
diff --git a/softwarecontext/imagenode.h b/softwarecontext/imagenode.h
index bfa7447a83..5b59da2f3b 100644
--- a/softwarecontext/imagenode.h
+++ b/softwarecontext/imagenode.h
@@ -21,7 +21,7 @@ public:
virtual void setVerticalWrapMode(QSGTexture::WrapMode wrapMode);
virtual void update();
- virtual void paint(QPainter *painter);
+ void paint(QPainter *painter);
private:
QRectF m_targetRect;
diff --git a/softwarecontext/rectanglenode.h b/softwarecontext/rectanglenode.h
index 2f1051df52..3405c8db84 100644
--- a/softwarecontext/rectanglenode.h
+++ b/softwarecontext/rectanglenode.h
@@ -22,7 +22,7 @@ public:
virtual void update();
- virtual void paint(QPainter *);
+ void paint(QPainter *);
private:
QRectF m_rect;
diff --git a/softwarecontext/renderingvisitor.cpp b/softwarecontext/renderingvisitor.cpp
new file mode 100644
index 0000000000..3a58600972
--- /dev/null
+++ b/softwarecontext/renderingvisitor.cpp
@@ -0,0 +1,81 @@
+#include "renderingvisitor.h"
+
+#include "imagenode.h"
+#include "rectanglenode.h"
+#include "glyphnode.h"
+
+RenderingVisitor::RenderingVisitor(QPainter *painter)
+ : painter(painter)
+{
+
+}
+
+void RenderingVisitor::visit(QSGTransformNode *node)
+{
+ painter->save();
+ painter->setTransform(node->matrix().toTransform(), /*combine*/true);
+}
+
+void RenderingVisitor::endVisit(QSGTransformNode *)
+{
+ painter->restore();
+}
+
+void RenderingVisitor::visit(QSGClipNode *node)
+{
+ painter->save();
+ painter->setClipRect(node->clipRect(), Qt::IntersectClip);
+}
+
+void RenderingVisitor::endVisit(QSGClipNode *)
+{
+ painter->restore();
+}
+
+void RenderingVisitor::visit(QSGGeometryNode *node)
+{
+ Q_UNREACHABLE();
+}
+
+void RenderingVisitor::endVisit(QSGGeometryNode *node)
+{
+ Q_UNREACHABLE();
+}
+
+void RenderingVisitor::visit(QSGOpacityNode *node)
+{
+ painter->save();
+ painter->setOpacity(node->opacity());
+}
+
+void RenderingVisitor::endVisit(QSGOpacityNode *node)
+{
+ painter->restore();
+}
+
+void RenderingVisitor::visit(QSGImageNode *node)
+{
+ static_cast<ImageNode*>(node)->paint(painter);
+}
+
+void RenderingVisitor::endVisit(QSGImageNode *)
+{
+}
+
+void RenderingVisitor::visit(QSGRectangleNode *node)
+{
+ static_cast<RectangleNode*>(node)->paint(painter);
+}
+
+void RenderingVisitor::endVisit(QSGRectangleNode *)
+{
+}
+
+void RenderingVisitor::visit(QSGGlyphNode *node)
+{
+ static_cast<GlyphNode*>(node)->paint(painter);
+}
+
+void RenderingVisitor::endVisit(QSGGlyphNode *)
+{
+}
diff --git a/softwarecontext/renderingvisitor.h b/softwarecontext/renderingvisitor.h
new file mode 100644
index 0000000000..213903aa5f
--- /dev/null
+++ b/softwarecontext/renderingvisitor.h
@@ -0,0 +1,30 @@
+#ifndef RENDERINGVISITOR_H
+#define RENDERINGVISITOR_H
+
+#include <private/qsgadaptationlayer_p.h>
+
+class RenderingVisitor : public QSGNodeVisitorEx
+{
+public:
+ RenderingVisitor(QPainter *painter);
+
+ virtual void visit(QSGTransformNode *node);
+ virtual void endVisit(QSGTransformNode *);
+ virtual void visit(QSGClipNode *node);
+ virtual void endVisit(QSGClipNode *node);
+ virtual void visit(QSGGeometryNode *node);
+ virtual void endVisit(QSGGeometryNode *node);
+ virtual void visit(QSGOpacityNode *node);
+ virtual void endVisit(QSGOpacityNode *node);
+ virtual void visit(QSGImageNode *node);
+ virtual void endVisit(QSGImageNode *node);
+ virtual void visit(QSGRectangleNode *node);
+ virtual void endVisit(QSGRectangleNode *node);
+ virtual void visit(QSGGlyphNode *node);
+ virtual void endVisit(QSGGlyphNode *node);
+
+private:
+ QPainter *painter;
+};
+
+#endif // RENDERINGVISITOR_H
diff --git a/softwarecontext/softwarecontext.pro b/softwarecontext/softwarecontext.pro
index 31bb122eaf..bde31d2773 100644
--- a/softwarecontext/softwarecontext.pro
+++ b/softwarecontext/softwarecontext.pro
@@ -12,7 +12,8 @@ SOURCES += \
rectanglenode.cpp \
imagenode.cpp \
pixmaptexture.cpp \
- glyphnode.cpp
+ glyphnode.cpp \
+ renderingvisitor.cpp
HEADERS += \
context.h \
@@ -21,7 +22,8 @@ HEADERS += \
rectanglenode.h \
imagenode.h \
pixmaptexture.h \
- glyphnode.h
+ glyphnode.h \
+ renderingvisitor.h
OTHER_FILES += softwarecontext.json