summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2012-02-14 12:31:11 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-20 10:28:18 +0100
commitcb9a213e540c5152a5c9634d590285fb4d231141 (patch)
tree5095e8aab425df28339bc93ebb47af44cb44709c /tests
parent330152354aed8496ac78d145e14b25ee2d7bf8fb (diff)
Added QSGRenderNode class.
Change-Id: I8c903cae490158b864af60f53c10c10f2faea7c0 Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtquick2/qtquick2.pro1
-rw-r--r--tests/auto/qtquick2/rendernode/data/MessUpState.qml32
-rw-r--r--tests/auto/qtquick2/rendernode/data/RenderOrder.qml53
-rw-r--r--tests/auto/qtquick2/rendernode/rendernode.pro18
-rw-r--r--tests/auto/qtquick2/rendernode/tst_rendernode.cpp242
5 files changed, 346 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qtquick2.pro b/tests/auto/qtquick2/qtquick2.pro
index 7066446cb1..7acd75f69e 100644
--- a/tests/auto/qtquick2/qtquick2.pro
+++ b/tests/auto/qtquick2/qtquick2.pro
@@ -4,6 +4,7 @@ PUBLICTESTS += \
examples \
geometry \
nodes \
+ rendernode \
qdeclarativepixmapcache
# This test requires the qtconcurrent module
diff --git a/tests/auto/qtquick2/rendernode/data/MessUpState.qml b/tests/auto/qtquick2/rendernode/data/MessUpState.qml
new file mode 100644
index 0000000000..58f6e80a2c
--- /dev/null
+++ b/tests/auto/qtquick2/rendernode/data/MessUpState.qml
@@ -0,0 +1,32 @@
+import QtQuick 2.0
+import Test 1.0
+
+Rectangle {
+ width: 200
+ height: 200
+ color: "black"
+ Rectangle {
+ width: 200
+ height: 100
+ anchors.centerIn: parent
+ clip: true
+ color: "white"
+ Rectangle {
+ width: 100
+ height: 100
+ anchors.centerIn: parent
+ rotation: 45
+ color: "blue"
+ clip: true
+ MessUpItem {
+ anchors.fill: parent
+ }
+ Rectangle {
+ anchors.fill: parent
+ anchors.margins: -50
+ color: "red"
+ opacity: 0.5
+ }
+ }
+ }
+}
diff --git a/tests/auto/qtquick2/rendernode/data/RenderOrder.qml b/tests/auto/qtquick2/rendernode/data/RenderOrder.qml
new file mode 100644
index 0000000000..3342756e06
--- /dev/null
+++ b/tests/auto/qtquick2/rendernode/data/RenderOrder.qml
@@ -0,0 +1,53 @@
+import QtQuick 2.0
+import Test 1.0
+
+Rectangle {
+ id: root
+
+ width: 200
+ height: 200
+ color: "black"
+
+ Rectangle {
+ width: 100
+ height: 100
+ anchors.top: parent.top
+ anchors.left: parent.left
+ color: "red"
+ opacity: 0.5
+ }
+
+ Rectangle {
+ width: 100
+ height: 100
+ anchors.bottom: parent.bottom
+ anchors.left: parent.left
+ color: "red"
+ }
+
+ ClearItem {
+ width: 100
+ height: 100
+ anchors.centerIn: parent
+ color: "white"
+ clip: true
+ }
+
+ Rectangle {
+ width: 100
+ height: 100
+ anchors.top: parent.top
+ anchors.right: parent.right
+ color: "blue"
+ }
+
+ Rectangle {
+ width: 100
+ height: 100
+ anchors.bottom: parent.bottom
+ anchors.right: parent.right
+ color: "blue"
+ opacity: 0.5
+ }
+
+}
diff --git a/tests/auto/qtquick2/rendernode/rendernode.pro b/tests/auto/qtquick2/rendernode/rendernode.pro
new file mode 100644
index 0000000000..f915a58900
--- /dev/null
+++ b/tests/auto/qtquick2/rendernode/rendernode.pro
@@ -0,0 +1,18 @@
+CONFIG += testcase
+TARGET = tst_rendernode
+SOURCES += tst_rendernode.cpp
+
+macx:CONFIG -= app_bundle
+
+testDataFiles.files = data
+testDataFiles.path = .
+DEPLOYMENT += testDataFiles
+
+include(../../shared/util.pri)
+
+CONFIG += parallel_test
+QT += core-private gui-private v8-private declarative-private quick-private testlib
+
+OTHER_FILES += \
+ data/RenderOrder.qml \
+ data/MessUpState.qml \
diff --git a/tests/auto/qtquick2/rendernode/tst_rendernode.cpp b/tests/auto/qtquick2/rendernode/tst_rendernode.cpp
new file mode 100644
index 0000000000..f0e385152e
--- /dev/null
+++ b/tests/auto/qtquick2/rendernode/tst_rendernode.cpp
@@ -0,0 +1,242 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+
+#include <QtQuick/qquickitem.h>
+#include <QtQuick/qquickview.h>
+#include <QtGui/qopenglcontext.h>
+#include <private/qsgrendernode_p.h>
+
+#include "../../shared/util.h"
+
+class tst_rendernode: public QDeclarativeDataTest
+{
+ Q_OBJECT
+public:
+ tst_rendernode();
+
+ QImage runTest(const QString &url)
+ {
+ QQuickView view;
+ view.setSource(QUrl(url));
+
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ return view.grabFrameBuffer();
+ }
+
+private slots:
+ void renderOrder();
+ void messUpState();
+};
+
+class ClearNode : public QSGRenderNode
+{
+public:
+ virtual StateFlags changedStates()
+ {
+ return ColorState;
+ }
+
+ virtual void render(const RenderState &)
+ {
+ // If clip has been set, scissoring will make sure the right area is cleared.
+ glClearColor(color.redF(), color.greenF(), color.blueF(), 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+
+ QColor color;
+};
+
+class ClearItem : public QQuickItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+public:
+ ClearItem() : m_color(Qt::black)
+ {
+ setFlag(ItemHasContents, true);
+ }
+
+ QColor color() const { return m_color; }
+ void setColor(const QColor &color)
+ {
+ if (color == m_color)
+ return;
+ m_color = color;
+ emit colorChanged();
+ }
+
+protected:
+ virtual QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+ {
+ ClearNode *node = static_cast<ClearNode *>(oldNode);
+ if (!node)
+ node = new ClearNode;
+ node->color = m_color;
+ return node;
+ }
+
+Q_SIGNALS:
+ void colorChanged();
+
+private:
+ QColor m_color;
+};
+
+class MessUpNode : public QSGRenderNode
+{
+public:
+ virtual StateFlags changedStates()
+ {
+ return StateFlags(DepthState) | StencilState | ScissorState | ColorState | BlendState
+ | CullState | ViewportState;
+ }
+
+ virtual void render(const RenderState &)
+ {
+ // Don't draw anything, just mess up the state
+ glViewport(10, 10, 10, 10);
+ glDisable(GL_SCISSOR_TEST);
+ glDepthMask(true);
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_EQUAL);
+#if defined(QT_OPENGL_ES)
+ glClearDepthf(1);
+#else
+ glClearDepth(1);
+#endif
+ glClearStencil(42);
+ glClearColor(1.0f, 0.5f, 1.0f, 0.0f);
+ glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+ glEnable(GL_SCISSOR_TEST);
+ glScissor(190, 190, 10, 10);
+ glStencilFunc(GL_EQUAL, 28, 0xff);
+ glBlendFunc(GL_ZERO, GL_ZERO);
+ GLint frontFace;
+ glGetIntegerv(GL_FRONT_FACE, &frontFace);
+ glFrontFace(frontFace == GL_CW ? GL_CCW : GL_CW);
+ glEnable(GL_CULL_FACE);
+ }
+};
+
+class MessUpItem : public QQuickItem
+{
+ Q_OBJECT
+public:
+ MessUpItem()
+ {
+ setFlag(ItemHasContents, true);
+ }
+
+protected:
+ virtual QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+ {
+ MessUpNode *node = static_cast<MessUpNode *>(oldNode);
+ if (!node)
+ node = new MessUpNode;
+ return node;
+ }
+};
+
+tst_rendernode::tst_rendernode()
+{
+ qmlRegisterType<ClearItem>("Test", 1, 0, "ClearItem");
+ qmlRegisterType<MessUpItem>("Test", 1, 0, "MessUpItem");
+}
+
+static void fuzzyCompareColor(QRgb x, QRgb y)
+{
+ QVERIFY(qAbs(qRed(x) - qRed(y)) < 4);
+ QVERIFY(qAbs(qGreen(x) - qGreen(y)) < 4);
+ QVERIFY(qAbs(qBlue(x) - qBlue(y)) < 4);
+}
+
+void tst_rendernode::renderOrder()
+{
+ QImage fb = runTest(testFile("RenderOrder.qml"));
+ int x1 = fb.width() / 8;
+ int x2 = fb.width() * 3 / 8;
+ int x3 = fb.width() * 5 / 8;
+ int x4 = fb.width() * 7 / 8;
+ int y1 = fb.height() / 8;
+ int y2 = fb.height() * 3 / 8;
+ int y3 = fb.height() * 5 / 8;
+ int y4 = fb.height() * 7 / 8;
+
+ fuzzyCompareColor(fb.pixel(x1, y1), qRgb(0x7f, 0x00, 0x00));
+ QCOMPARE(fb.pixel(x2, y2), qRgb(0xff, 0xff, 0xff));
+ QCOMPARE(fb.pixel(x3, y2), qRgb(0x00, 0x00, 0xff));
+ QCOMPARE(fb.pixel(x4, y1), qRgb(0x00, 0x00, 0xff));
+ QCOMPARE(fb.pixel(x1, y4), qRgb(0xff, 0x00, 0x00));
+ QCOMPARE(fb.pixel(x2, y3), qRgb(0xff, 0xff, 0xff));
+ fuzzyCompareColor(fb.pixel(x3, y3), qRgb(0x7f, 0x7f, 0xff));
+ fuzzyCompareColor(fb.pixel(x4, y4), qRgb(0x00, 0x00, 0x7f));
+}
+
+void tst_rendernode::messUpState()
+{
+ QImage fb = runTest(testFile("MessUpState.qml"));
+ int x1 = 0;
+ int x2 = fb.width() / 2;
+ int x3 = fb.width() - 1;
+ int y1 = 0;
+ int y2 = fb.height() * 3 / 16;
+ int y3 = fb.height() / 2;
+ int y4 = fb.height() * 13 / 16;
+ int y5 = fb.height() - 1;
+
+ QCOMPARE(fb.pixel(x1, y3), qRgb(0xff, 0xff, 0xff));
+ QCOMPARE(fb.pixel(x3, y3), qRgb(0xff, 0xff, 0xff));
+
+ QCOMPARE(fb.pixel(x2, y1), qRgb(0x00, 0x00, 0x00));
+ QCOMPARE(fb.pixel(x2, y2), qRgb(0x00, 0x00, 0x00));
+ fuzzyCompareColor(fb.pixel(x2, y3), qRgb(0x7f, 0x00, 0x7f));
+ QCOMPARE(fb.pixel(x2, y4), qRgb(0x00, 0x00, 0x00));
+ QCOMPARE(fb.pixel(x2, y5), qRgb(0x00, 0x00, 0x00));
+}
+
+
+QTEST_MAIN(tst_rendernode)
+
+#include "tst_rendernode.moc"