aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2015-08-10 14:33:14 +0300
committerMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2015-08-20 09:49:18 +0000
commit3f4d7a755585f1b79c7e9675220b8210f10f358e (patch)
tree50e4e4faef56413bede418bcf495ca7fe41677ba /tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
parent04f30db289225e700fe99c163f53f0dd7e920caf (diff)
Add possibility to mirror ShaderEffectSource generated textures
Using textures generated by ShaderEffectSource items (or Item.layer) with custom OpenGL code was non-intuitive due to mismatching coordinate systems, so added a possibility to control the generated texture orientation. [ChangeLog][QtQuick][ShaderEffectSource] Added possibility to mirror generated OpenGL texture. Change-Id: I7c03d8b6fbfc43d69812c15d244200fb8e7c7bb9 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp')
-rw-r--r--tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
index 25a75c0580..094b69c07f 100644
--- a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
+++ b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
@@ -87,7 +87,12 @@ private slots:
void itemEffect();
void rectangleEffect();
+ void textureMirroring_data();
+ void textureMirroring();
+
private:
+ void mirroringCheck(int mirroring, int x, bool shouldMirror, const QImage &fb);
+
bool m_isMesaSoftwareRasterizer;
int m_mesaVersion;
};
@@ -434,6 +439,94 @@ void tst_QQuickItemLayer::rectangleEffect()
QCOMPARE(fb.pixel(0, 100), qRgb(0, 0, 0xff));
}
+void tst_QQuickItemLayer::textureMirroring_data()
+{
+ QTest::addColumn<int>("mirroring");
+
+ QTest::newRow("no mirroring") << 0;
+ QTest::newRow("horizontal") << 1;
+ QTest::newRow("vertical") << 2;
+ QTest::newRow("horizontal | vertical") << 3;
+}
+
+void tst_QQuickItemLayer::textureMirroring()
+{
+ QFETCH(int, mirroring);
+
+ QQuickView view;
+ view.setSource(testFileUrl("TextureMirroring.qml"));
+
+ QQuickItem *child = view.contentItem()->childItems().at(0);
+ child->setProperty("mirroring", mirroring);
+
+ view.show();
+
+ QTest::qWaitForWindowExposed(&view);
+
+ QImage fb = view.grabWindow();
+
+ // Mirroring should have no visual effect on layered item without shader effect
+ mirroringCheck(mirroring, 0, false, fb);
+
+ // Mirroring should have visual effect on layered item with shader effect
+ mirroringCheck(mirroring, 50, true, fb);
+
+ // Mirroring should have no visual effect on source item for ShaderEffectSource
+ mirroringCheck(mirroring, 100, false, fb);
+
+ // Mirroring should have no visual effect on ShaderEffectSource item
+ mirroringCheck(mirroring, 150, false, fb);
+
+ // Mirroring should have visual effect on ShaderEffect item itself
+ mirroringCheck(mirroring, 200, true, fb);
+}
+
+void tst_QQuickItemLayer::mirroringCheck(int mirroring, int x, bool shouldMirror, const QImage &fb)
+{
+ int offset = 10;
+ int spacing = 25;
+
+ if (shouldMirror) {
+ switch (mirroring) {
+ case 0: { // No mirroring -> Visually Y gets swapped, X is default
+ QCOMPARE(fb.pixel(x + offset, offset), qRgb(0, 0xff, 0));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0, 0, 0));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0xff, 0, 0));
+ break;
+ }
+ case 1: { // Horizontal mirroring -> Visually both X and Y get swapped, as neither is default
+ QCOMPARE(fb.pixel(x + offset, offset), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0, 0xff, 0));
+ QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0, 0, 0));
+ break;
+ }
+ case 2: { // Vertical mirroring -> The default case, nothing gets swapped
+ QCOMPARE(fb.pixel(x + offset, offset), qRgb(0, 0, 0));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0, 0xff, 0));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0, 0, 0xff));
+ break;
+ }
+ case 3: { // Both axes mirrored -> Visually X gets swapped, Y is default
+ QCOMPARE(fb.pixel(x + offset, offset), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0, 0, 0));
+ QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0, 0, 0xff));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0, 0xff, 0));
+ break;
+ }
+ default:
+ qWarning() << "Invalid case!";
+ break;
+ }
+ } else {
+ QCOMPARE(fb.pixel(x + offset, offset), qRgb(0, 0, 0));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset), qRgb(0xff, 0, 0));
+ QCOMPARE(fb.pixel(x + offset, offset + spacing), qRgb(0, 0xff, 0));
+ QCOMPARE(fb.pixel(x + offset + spacing, offset + spacing), qRgb(0, 0, 0xff));
+ }
+}
QTEST_MAIN(tst_QQuickItemLayer)