aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickitemlayer
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-02-16 14:43:03 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-24 04:51:31 +0100
commitb855240b782395f94315f43ea3e7e182299fac48 (patch)
treebc594c04449be8cd14cd0ab0bb72dafc2be0ffb2 /tests/auto/quick/qquickitemlayer
parent6a42a6e0a9a1abdda0d07a5a20b4ac7e45348684 (diff)
Rename QDeclarative symbols to QQuick and QQml
Symbols beginning with QDeclarative are already exported by the quick1 module. Users can apply the bin/rename-qtdeclarative-symbols.sh script to modify client code using the previous names of the renamed symbols. Task-number: QTBUG-23737 Change-Id: Ifaa482663767634931e8711a8e9bf6e404859e66 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickitemlayer')
-rw-r--r--tests/auto/quick/qquickitemlayer/data/DisableLayer.qml18
-rw-r--r--tests/auto/quick/qquickitemlayer/data/Effect.qml34
-rw-r--r--tests/auto/quick/qquickitemlayer/data/Enabled.qml25
-rw-r--r--tests/auto/quick/qquickitemlayer/data/ItemEffect.qml23
-rw-r--r--tests/auto/quick/qquickitemlayer/data/Mipmap.qml30
-rw-r--r--tests/auto/quick/qquickitemlayer/data/RectangleEffect.qml22
-rw-r--r--tests/auto/quick/qquickitemlayer/data/SamplerNameChange.qml18
-rw-r--r--tests/auto/quick/qquickitemlayer/data/Smooth.qml23
-rw-r--r--tests/auto/quick/qquickitemlayer/data/SourceRect.qml33
-rw-r--r--tests/auto/quick/qquickitemlayer/data/TextureProvider.qml40
-rw-r--r--tests/auto/quick/qquickitemlayer/data/ToggleLayerAndEffect.qml23
-rw-r--r--tests/auto/quick/qquickitemlayer/data/Visible.qml56
-rw-r--r--tests/auto/quick/qquickitemlayer/data/ZOrder.qml52
-rw-r--r--tests/auto/quick/qquickitemlayer/data/ZOrderChange.qml50
-rw-r--r--tests/auto/quick/qquickitemlayer/qquickitemlayer.pro38
-rw-r--r--tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp436
16 files changed, 921 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitemlayer/data/DisableLayer.qml b/tests/auto/quick/qquickitemlayer/data/DisableLayer.qml
new file mode 100644
index 0000000000..70fc05e937
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/DisableLayer.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+Item {
+ width: 200
+ height: 200
+ Rectangle {
+ width: 100
+ height: 100
+ color: "red"
+ layer.enabled: true
+ Component.onCompleted: {
+ layer.enabled = false
+ visible = false
+ width = 120
+ x = 10
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/Effect.qml b/tests/auto/quick/qquickitemlayer/data/Effect.qml
new file mode 100644
index 0000000000..630c8f90ed
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/Effect.qml
@@ -0,0 +1,34 @@
+import QtQuick 2.0
+
+Item
+{
+ width: 100
+ height: 100
+
+ Rectangle {
+ id: box
+ width: 100
+ height: 100
+
+ color: "#0000ff"
+
+ Rectangle {
+ x: 50
+ width: 50
+ height: 100
+ color: "#00ff00"
+ }
+
+ layer.enabled: true
+ layer.effect: ShaderEffect {
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = texture2D(source, qt_TexCoord0).bgra * qt_Opacity;
+ }"
+ }
+
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/Enabled.qml b/tests/auto/quick/qquickitemlayer/data/Enabled.qml
new file mode 100644
index 0000000000..0e7d4f56b8
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/Enabled.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.0
+
+Item
+{
+ width: 200
+ height: 200
+
+ Item {
+ width: 20
+ height: 20
+ scale: 10
+
+ layer.enabled: true
+ anchors.centerIn: parent
+
+ Rectangle {
+ width: 20
+ height: 20
+ gradient: Gradient {
+ GradientStop { position: 0; color: "white" }
+ GradientStop { position: 1; color: "black" }
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/ItemEffect.qml b/tests/auto/quick/qquickitemlayer/data/ItemEffect.qml
new file mode 100644
index 0000000000..2f17d78efd
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/ItemEffect.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.0
+
+Item {
+ width: 200
+ height: 200
+ Rectangle {
+ anchors.fill: parent
+ anchors.margins: 99
+ gradient: Gradient {
+ GradientStop { position: 0.3; color: "red" }
+ GradientStop { position: 0.7; color: "blue" }
+ }
+ layer.enabled: true
+ layer.effect: Item {
+ property variant source
+ ShaderEffect {
+ anchors.fill: parent
+ anchors.margins: -99
+ property variant source: parent.source
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/Mipmap.qml b/tests/auto/quick/qquickitemlayer/data/Mipmap.qml
new file mode 100644
index 0000000000..8de41076e9
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/Mipmap.qml
@@ -0,0 +1,30 @@
+import QtQuick 2.0
+
+Item
+{
+ width: 100
+ height: 100
+
+ Rectangle {
+ id: box
+ width: 600
+ height: 600
+
+ scale: 1 / 6.
+
+ color: "black"
+
+ layer.enabled: true
+ layer.mipmap: true
+ layer.smooth: true
+
+ anchors.centerIn: parent
+
+ Rectangle {
+ x: 1
+ width: 1
+ height: parent.height
+ color: "white"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/RectangleEffect.qml b/tests/auto/quick/qquickitemlayer/data/RectangleEffect.qml
new file mode 100644
index 0000000000..94c43f2caf
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/RectangleEffect.qml
@@ -0,0 +1,22 @@
+import QtQuick 2.0
+
+Item {
+ width: 200
+ height: 200
+ Rectangle {
+ width: 100
+ height: 100
+ x: 50
+ y: 50
+ scale: 1.5
+ z: 1
+ rotation: 45
+ color: "#ff0000"
+ layer.enabled: true
+ layer.effect: Rectangle { color: "#0000ff" }
+ }
+ Rectangle {
+ anchors.fill: parent
+ color: "#00ff00"
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/SamplerNameChange.qml b/tests/auto/quick/qquickitemlayer/data/SamplerNameChange.qml
new file mode 100644
index 0000000000..a4c2ebff6b
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/SamplerNameChange.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 200
+ height: 200
+ color: "blue"
+ layer.enabled: true
+ layer.effect: ShaderEffect {
+ fragmentShader: "
+ uniform sampler2D foo;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = texture2D(foo, qt_TexCoord0) * qt_Opacity;
+ }"
+ }
+ Component.onCompleted: layer.samplerName = "foo"
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/Smooth.qml b/tests/auto/quick/qquickitemlayer/data/Smooth.qml
new file mode 100644
index 0000000000..3f9575bb0b
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/Smooth.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.0
+
+
+Item {
+ width: 200
+ height: 100
+
+ Row {
+ id: layerRoot
+
+ width: 20
+ height: 10
+
+ Rectangle { width: 10; height: 10; color: "red" }
+ Rectangle { width: 10; height: 10; color: "blue" }
+
+ layer.enabled: true
+ layer.smooth: true
+
+ anchors.centerIn: parent
+ scale: 10
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/SourceRect.qml b/tests/auto/quick/qquickitemlayer/data/SourceRect.qml
new file mode 100644
index 0000000000..7cc7e8b21e
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/SourceRect.qml
@@ -0,0 +1,33 @@
+import QtQuick 2.0
+
+Item
+{
+ width: 100
+ height: 100
+
+ Rectangle {
+ id: box
+ width: 100
+ height: 100
+
+ color: "#ff0000"
+
+ layer.enabled: true
+ layer.sourceRect: Qt.rect(-10, -10, box.width + 20, box.height + 20);
+
+ // A shader that pads the transparent pixels with blue.
+ layer.effect: ShaderEffect {
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ vec4 c = texture2D(source, qt_TexCoord0);
+ if (c.a == 0.)
+ c = vec4(0, 0, 1, 1);
+ gl_FragColor = c * qt_Opacity;
+ }
+ "
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/TextureProvider.qml b/tests/auto/quick/qquickitemlayer/data/TextureProvider.qml
new file mode 100644
index 0000000000..ccd515652a
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/TextureProvider.qml
@@ -0,0 +1,40 @@
+import QtQuick 2.0
+
+Item
+{
+ width: 100
+ height: 100
+
+ Rectangle {
+ id: box
+ width: 100
+ height: 100
+
+ color: "#0000ff"
+
+ Rectangle {
+ x: 50
+ width: 50
+ height: 100
+ color: "#00ff00"
+ }
+
+ visible: false
+
+ layer.enabled: true
+ }
+
+ ShaderEffect {
+ anchors.fill: parent
+ property variant source: box
+
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = texture2D(source, qt_TexCoord0).bgra * qt_Opacity;
+ }"
+ }
+
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/ToggleLayerAndEffect.qml b/tests/auto/quick/qquickitemlayer/data/ToggleLayerAndEffect.qml
new file mode 100644
index 0000000000..174b669b6c
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/ToggleLayerAndEffect.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.0
+
+Item {
+ width: 200
+ height: 200
+ Rectangle {
+ width: 100
+ height: 100
+ color: "red"
+ Component.onCompleted: {
+ layer.enabled = true
+ layer.effect = effectComponent
+ layer.enabled = false
+ visible = false
+ width = 120
+ x = 10
+ }
+ }
+ Component {
+ id: effectComponent
+ ShaderEffect { }
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/Visible.qml b/tests/auto/quick/qquickitemlayer/data/Visible.qml
new file mode 100644
index 0000000000..8267f18250
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/Visible.qml
@@ -0,0 +1,56 @@
+import QtQuick 2.0
+
+Item
+{
+ id: root
+
+ width: 100
+ height: 100
+
+ property bool layerEffect: false;
+ onLayerEffectChanged: root.maybeUse();
+ Component.onCompleted: root.maybeUse();
+
+ property real layerOpacity: 1;
+ property bool layerVisible: true;
+
+ function maybeUse() {
+ if (root.layerEffect)
+ box.layer.effect = shaderEffect
+ }
+
+ Component {
+ id: shaderEffect
+ ShaderEffect {
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = texture2D(source, qt_TexCoord0).bgra * qt_Opacity;
+ }
+ "
+ }
+
+ }
+
+ Rectangle {
+ id: box
+ width: 100
+ height: 100
+
+ color: "#0000ff"
+ visible: parent.layerVisible;
+ opacity: parent.layerOpacity;
+
+ Rectangle {
+ x: 50
+ width: 50
+ height: 100
+ color: "#00ff00"
+ }
+
+ layer.enabled: true
+
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/ZOrder.qml b/tests/auto/quick/qquickitemlayer/data/ZOrder.qml
new file mode 100644
index 0000000000..59ccb32224
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/ZOrder.qml
@@ -0,0 +1,52 @@
+import QtQuick 2.0
+
+Item
+{
+ id: root
+
+ width: 200
+ height: 200
+
+ Component {
+ id: shaderEffect
+ ShaderEffect { }
+ }
+
+ property bool layerEffect: false;
+ onLayerEffectChanged: root.maybeUse();
+ Component.onCompleted: root.maybeUse();
+
+ function maybeUse() {
+ if (root.layerEffect)
+ box.layer.effect = shaderEffect
+ }
+
+
+ Rectangle {
+ color: "red"
+ anchors.left: parent.left
+ anchors.top: parent.top
+ width: 100
+ height: 100
+ z: 1
+ }
+
+ Rectangle {
+ color: "#00ff00"
+ anchors.bottom: parent.bottom
+ anchors.right: parent.right
+ width: 100
+ height: 100
+ z: 3
+ }
+
+ Rectangle {
+ id: box
+ color: "blue"
+ anchors.fill: parent
+ anchors.margins: 10
+ layer.enabled: true
+ z: 2
+ }
+
+}
diff --git a/tests/auto/quick/qquickitemlayer/data/ZOrderChange.qml b/tests/auto/quick/qquickitemlayer/data/ZOrderChange.qml
new file mode 100644
index 0000000000..ebbd3b7e15
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/data/ZOrderChange.qml
@@ -0,0 +1,50 @@
+import QtQuick 2.0
+
+Item {
+ width: 200
+ height: 200
+ property bool layerEffect: false
+ property bool layerEnabled: false
+ property real layerZ: 0
+ Rectangle {
+ anchors.fill: parent
+ color: "#00ffff"
+ }
+ Rectangle {
+ id: foo
+ anchors.fill: parent
+ color: "#ffff00"
+ Rectangle {
+ width: 100
+ height: 100
+ color: "#00ffff"
+ }
+ layer.enabled: parent.layerEnabled
+ layer.effect: parent.layerEffect ? effectComponent : null
+ opacity: 0.5
+ z: layerZ
+ }
+ Rectangle {
+ width: 100
+ height: 100
+ x: 100
+ color: "#ff0000"
+ }
+ Rectangle {
+ width: 100
+ height: 100
+ y: 100
+ color: "#0000ff"
+ z: 1
+ }
+ Component {
+ id: effectComponent
+ ShaderEffect {
+ fragmentShader: "
+ uniform sampler2D source;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main() { gl_FragColor = texture2D(source, qt_TexCoord0).xzyw * qt_Opacity; }"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro
new file mode 100644
index 0000000000..a2d5f401ff
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro
@@ -0,0 +1,38 @@
+CONFIG += testcase
+TARGET = tst_qquickitemlayer
+SOURCES += tst_qquickitemlayer.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 qml-private quick-private testlib
+
+OTHER_FILES += \
+ data/Smooth.qml \
+ data/Enabled.qml \
+ data/Mipmap.qml \
+ data/Effect.qml \
+ data/SourceRect.qml \
+ data/TextureProvider.qml \
+ data/Visible.qml \
+ data/ZOrder.qml \
+ data/ZOrderChange.qml \
+ data/ToggleLayerAndEffect.qml \
+ data/DisableLayer.qml \
+ data/SamplerNameChange.qml \
+ data/ItemEffect.qml \
+ data/RectangleEffect.qml
+
+
+
+
+
+
+
+
diff --git a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
new file mode 100644
index 0000000000..44d0d6d09c
--- /dev/null
+++ b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
@@ -0,0 +1,436 @@
+/****************************************************************************
+**
+** 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 "../../shared/util.h"
+
+class tst_QQuickItemLayer: public QQmlDataTest
+{
+ Q_OBJECT
+public:
+ tst_QQuickItemLayer();
+
+ QImage runTest(const QString &url)
+ {
+ QQuickView view;
+ view.setSource(QUrl(url));
+
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ return view.grabFrameBuffer();
+ }
+
+private slots:
+ void layerEnabled();
+ void layerSmooth();
+ void layerMipmap();
+ void layerEffect();
+
+ void layerVisibility_data();
+ void layerVisibility();
+
+ void layerSourceRect();
+
+ void layerZOrder_data();
+ void layerZOrder();
+
+ void layerIsTextureProvider();
+
+ void changeZOrder_data();
+ void changeZOrder();
+
+ void toggleLayerAndEffect();
+ void disableLayer();
+ void changeSamplerName();
+ void itemEffect();
+ void rectangleEffect();
+
+private:
+ bool m_isMesaSoftwareRasterizer;
+ int m_mesaVersion;
+};
+
+tst_QQuickItemLayer::tst_QQuickItemLayer()
+ : m_mesaVersion(0)
+{
+ QWindow window;
+ QOpenGLContext context;
+ window.setSurfaceType(QWindow::OpenGLSurface);
+ window.create();
+ context.create();
+ context.makeCurrent(&window);
+ const char *vendor = (const char *)glGetString(GL_VENDOR);
+ const char *renderer = (const char *)glGetString(GL_RENDERER);
+ m_isMesaSoftwareRasterizer = strcmp(vendor, "Mesa Project") == 0
+ && strcmp(renderer, "Software Rasterizer") == 0;
+ if (m_isMesaSoftwareRasterizer) {
+ // Expects format: <OpenGL version> Mesa <Mesa version>[-devel] [...]
+ const char *version = (const char *)glGetString(GL_VERSION);
+ QList<QByteArray> list = QByteArray(version).split(' ');
+ if (list.size() >= 3) {
+ list = list.at(2).split('-').at(0).split('.');
+ int major = 0;
+ int minor = 0;
+ int patch = 0;
+ if (list.size() >= 1)
+ major = list.at(0).toInt();
+ if (list.size() >= 2)
+ minor = list.at(1).toInt();
+ if (list.size() >= 3)
+ patch = list.at(2).toInt();
+ m_mesaVersion = QT_VERSION_CHECK(major, minor, patch);
+ }
+ }
+}
+
+// The test draws a red and a blue box next to each other and tests that the
+// output is still red and blue on the left and right and a combination of
+// the two in the middle.
+
+void tst_QQuickItemLayer::layerSmooth()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+ QImage fb = runTest(testFile("Smooth.qml"));
+ QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0, 0xff));
+
+ uint pixel = fb.pixel(fb.width() / 2, 0);
+ QVERIFY(qRed(pixel) > 0);
+ QVERIFY(qBlue(pixel) > 0);
+}
+
+
+
+// The test draws a gradient at a small size into a layer and scales the
+// layer. If the layer is enabled there should be very visible bands in
+// the gradient.
+
+void tst_QQuickItemLayer::layerEnabled()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+ QImage fb = runTest(testFile("Enabled.qml"));
+ // Verify the banding
+ QCOMPARE(fb.pixel(0, 0), fb.pixel(0, 1));
+ // Verify the gradient
+ QVERIFY(fb.pixel(0, 0) != fb.pixel(0, fb.height() - 1));
+}
+
+
+
+// The test draws a one pixel wide line and scales it down by more than a a factor 2
+// If mipmpping works, the pixels should be gray, not white or black
+
+void tst_QQuickItemLayer::layerMipmap()
+{
+ if (m_isMesaSoftwareRasterizer)
+ QSKIP("Mipmapping does not work with the Mesa Software Rasterizer.");
+ QImage fb = runTest(testFile("Mipmap.qml"));
+ QVERIFY(fb.pixel(0, 0) != 0xff000000);
+ QVERIFY(fb.pixel(0, 0) != 0xffffffff);
+}
+
+
+
+// The test implements an rgb swapping effect sourced from a blue rectangle. The
+// resulting pixel should be red
+
+void tst_QQuickItemLayer::layerEffect()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+ QImage fb = runTest(testFile("Effect.qml"));
+ QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0xff, 0));
+}
+
+
+
+// The test draws a rectangle and verifies that there is padding on each side
+// as the source rect spans outside the item. The padding is verified using
+// a shader that pads transparent to blue. Everything else is red.
+void tst_QQuickItemLayer::layerSourceRect()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+
+ QImage fb = runTest(testFile("SourceRect.qml"));
+
+ // Check that the edges are converted to blue
+ QCOMPARE(fb.pixel(0, 0), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(0, fb.height() - 1), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(fb.width() - 1, fb.height() - 1), qRgb(0, 0, 0xff));
+
+ // The center pixel should be red
+ QCOMPARE(fb.pixel(fb.width() / 2, fb.height() / 2), qRgb(0xff, 0, 0));
+}
+
+
+
+// Same as the effect test up above, but this time use the item
+// directly in a stand alone ShaderEffect
+void tst_QQuickItemLayer::layerIsTextureProvider()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+ QImage fb = runTest(testFile("TextureProvider.qml"));
+ QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0xff, 0));
+}
+
+
+void tst_QQuickItemLayer::layerVisibility_data()
+{
+ QTest::addColumn<bool>("visible");
+ QTest::addColumn<bool>("effect");
+ QTest::addColumn<qreal>("opacity");
+
+ QTest::newRow("!effect, !visible, a=1") << false << false << 1.;
+ QTest::newRow("!effect, visible, a=1") << false << true << 1.;
+ QTest::newRow("effect, !visible, a=1") << true << false << 1.;
+ QTest::newRow("effect, visible, a=1") << true << true << 1.;
+
+ QTest::newRow("!effect, !visible, a=.5") << false << false << .5;
+ QTest::newRow("!effect, visible, a=.5") << false << true << .5;
+ QTest::newRow("effect, !visible, a=.5") << true << false << .5;
+ QTest::newRow("effect, visible, a=.5") << true << true << .5;
+
+ QTest::newRow("!effect, !visible, a=0") << false << false << 0.;
+ QTest::newRow("!effect, visible, a=0") << false << true << 0.;
+ QTest::newRow("effect, !visible, a=0") << true << false << 0.;
+ QTest::newRow("effect, visible, a=0") << true << true << 0.;
+}
+
+void tst_QQuickItemLayer::layerVisibility()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+
+ QFETCH(bool, visible);
+ QFETCH(bool, effect);
+ QFETCH(qreal, opacity);
+
+ QQuickView view;
+ view.setSource(testFile("Visible.qml"));
+
+ QQuickItem *child = view.rootItem()->childItems().at(0);
+ child->setProperty("layerVisible", visible);
+ child->setProperty("layerEffect", effect);
+ child->setProperty("layerOpacity", opacity);
+
+ view.show();
+
+ QTest::qWaitForWindowShown(&view);
+
+ QImage fb = view.grabFrameBuffer();
+ uint pixel = fb.pixel(0, 0);
+
+ if (!visible || opacity == 0) {
+ QCOMPARE(pixel, qRgb(0xff, 0xff, 0xff));
+ } else if (effect) {
+ QCOMPARE(qRed(pixel), 0xff);
+ QVERIFY(qGreen(pixel) < 0xff);
+ QVERIFY(qBlue(pixel) < 0xff);
+ } else { // no effect
+ QCOMPARE(qBlue(pixel), 0xff);
+ QVERIFY(qGreen(pixel) < 0xff);
+ QVERIFY(qRed(pixel) < 0xff);
+ }
+}
+
+
+
+
+void tst_QQuickItemLayer::layerZOrder_data()
+{
+ QTest::addColumn<bool>("effect");
+
+ QTest::newRow("!effect") << false;
+ QTest::newRow("effect") << true;
+}
+
+void tst_QQuickItemLayer::layerZOrder()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+
+ QFETCH(bool, effect);
+
+ QQuickView view;
+ view.setSource(testFile("ZOrder.qml"));
+
+ QQuickItem *child = view.rootItem()->childItems().at(0);
+ child->setProperty("layerEffect", effect);
+
+ view.show();
+
+ QTest::qWaitForWindowShown(&view);
+
+ QImage fb = view.grabFrameBuffer();
+
+ QCOMPARE(fb.pixel(50, 50), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(150, 150), qRgb(0, 0xff, 00));
+
+}
+
+void tst_QQuickItemLayer::changeZOrder_data()
+{
+ QTest::addColumn<bool>("layered");
+ QTest::addColumn<bool>("effect");
+
+ QTest::newRow("layered, effect") << true << true;
+ QTest::newRow("layered, !effect") << true << false;
+ QTest::newRow("!layered") << false << false;
+}
+
+void tst_QQuickItemLayer::changeZOrder()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+
+ QFETCH(bool, layered);
+ QFETCH(bool, effect);
+
+ QQuickView view;
+ view.setSource(testFile("ZOrderChange.qml"));
+
+ QQuickItem *child = view.rootItem()->childItems().at(0);
+ child->setProperty("layerEnabled", layered);
+ child->setProperty("layerEffect", effect);
+ child->setProperty("layerZ", 1);
+
+ view.show();
+
+ QTest::qWaitForWindowShown(&view);
+
+ QImage fb = view.grabFrameBuffer();
+
+ QRgb topLeft = fb.pixel(50, 50);
+ QRgb topRight = fb.pixel(150, 50);
+ QRgb bottomLeft = fb.pixel(50, 150);
+ QRgb bottomRight = fb.pixel(150, 150);
+
+ QCOMPARE(bottomLeft, qRgb(0, 0, 0xff));
+
+ if (layered) {
+ QCOMPARE(topLeft, qRgb(0, 0xff, 0xff));
+ } else {
+ QCOMPARE(qGreen(topLeft), 0xff);
+ QVERIFY(qAbs(qRed(topLeft) - 0x3f) < 4);
+ QVERIFY(qAbs(qBlue(topLeft) - 0xbf) < 4);
+ }
+
+ if (layered && effect) {
+ QCOMPARE(qRed(topRight), 0xff);
+ QCOMPARE(qGreen(topRight), 0x00);
+ QVERIFY(qAbs(qBlue(topRight) - 0x7f) < 4);
+
+ QVERIFY(qAbs(qRed(bottomRight) - 0x7f) < 4);
+ QCOMPARE(qBlue(bottomRight), 0xff);
+ QVERIFY(qAbs(qGreen(bottomRight) - 0x7f) < 4);
+ } else {
+ QCOMPARE(qRed(topRight), 0xff);
+ QCOMPARE(qBlue(topRight), 0x00);
+ QVERIFY(qAbs(qGreen(topRight) - 0x7f) < 4);
+
+ QVERIFY(qAbs(qRed(bottomRight) - 0x7f) < 4);
+ QCOMPARE(qGreen(bottomRight), 0xff);
+ QVERIFY(qAbs(qBlue(bottomRight) - 0x7f) < 4);
+ }
+}
+
+void tst_QQuickItemLayer::toggleLayerAndEffect()
+{
+ // This test passes if it doesn't crash.
+ runTest(testFile("ToggleLayerAndEffect.qml"));
+}
+
+void tst_QQuickItemLayer::disableLayer()
+{
+ // This test passes if it doesn't crash.
+ runTest(testFile("DisableLayer.qml"));
+}
+
+void tst_QQuickItemLayer::changeSamplerName()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+ QImage fb = runTest(testFile("SamplerNameChange.qml"));
+ QCOMPARE(fb.pixel(0, 0), qRgb(0, 0, 0xff));
+}
+
+void tst_QQuickItemLayer::itemEffect()
+{
+ if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0))
+ QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly.");
+ QImage fb = runTest(testFile("ItemEffect.qml"));
+ QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(199, 0), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(0, 199), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(199, 199), qRgb(0, 0, 0xff));
+}
+
+void tst_QQuickItemLayer::rectangleEffect()
+{
+ QImage fb = runTest(testFile("RectangleEffect.qml"));
+ QCOMPARE(fb.pixel(0, 0), qRgb(0, 0xff, 0));
+ QCOMPARE(fb.pixel(199, 0), qRgb(0, 0xff, 0));
+ QCOMPARE(fb.pixel(0, 199), qRgb(0, 0xff, 0));
+ QCOMPARE(fb.pixel(199, 199), qRgb(0, 0xff, 0));
+
+ QCOMPARE(fb.pixel(100, 0), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(199, 100), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(100, 199), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(0, 100), qRgb(0, 0, 0xff));
+}
+
+
+QTEST_MAIN(tst_QQuickItemLayer)
+
+#include "tst_qquickitemlayer.moc"