diff options
Diffstat (limited to 'tests/auto/quick/qquickitemlayer')
3 files changed, 254 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickitemlayer/data/TextureMirroring.qml b/tests/auto/quick/qquickitemlayer/data/TextureMirroring.qml new file mode 100644 index 0000000000..2827960153 --- /dev/null +++ b/tests/auto/quick/qquickitemlayer/data/TextureMirroring.qml @@ -0,0 +1,159 @@ +import QtQuick 2.6 + +Item +{ + width: 250 + height: 50 + + property int mirroring: 0 + + // Layered box without effect. Mirroring should not affect how it looks. + Rectangle { + x: 0 + y: 0 + width: 50 + height: 50 + layer.enabled: true + layer.textureMirroring: mirroring + Rectangle { + x: 0 + y: 0 + width: 25 + height: 25 + color: "#000000" + } + Rectangle { + x: 25 + y: 0 + width: 25 + height: 25 + color: "#ff0000" + } + Rectangle { + x: 0 + y: 25 + width: 25 + height: 25 + color: "#00ff00" + } + Rectangle { + x: 25 + y: 25 + width: 25 + height: 25 + color: "#0000ff" + } + } + + // Layered box with effect. Mirroring should affect how it looks. + Rectangle { + id: layeredEffectBox + x: 50 + y: 0 + width: 50 + height: 50 + layer.enabled: true + layer.textureMirroring: mirroring + layer.samplerName: "source" + layer.effect: ShaderEffect { + property variant source: layeredEffectBox + fragmentShader: " + uniform lowp sampler2D source; + varying highp vec2 qt_TexCoord0; + void main() { + gl_FragColor = texture2D(source, qt_TexCoord0); + }" + + } + + Rectangle { + x: 0 + y: 0 + width: 25 + height: 25 + color: "#000000" + } + Rectangle { + x: 25 + y: 0 + width: 25 + height: 25 + color: "#ff0000" + } + Rectangle { + x: 0 + y: 25 + width: 25 + height: 25 + color: "#00ff00" + } + Rectangle { + x: 25 + y: 25 + width: 25 + height: 25 + color: "#0000ff" + } + } + + // Non-layered source item for ShaderEffectSource. Mirroring should not affect how it looks. + Rectangle { + id: box2 + x: 100 + y: 0 + width: 50 + height: 50 + Rectangle { + x: 0 + y: 0 + width: 25 + height: 25 + color: "#000000" + } + Rectangle { + x: 25 + y: 0 + width: 25 + height: 25 + color: "#ff0000" + } + Rectangle { + x: 0 + y: 25 + width: 25 + height: 25 + color: "#00ff00" + } + Rectangle { + x: 25 + y: 25 + width: 25 + height: 25 + color: "#0000ff" + } + } + // ShaderEffectSource item. Mirroring should not affect how it looks. + ShaderEffectSource { + id: theSource + x: 150 + y: 0 + width: 50 + height: 50 + sourceItem: box2 + textureMirroring: mirroring + } + // ShaderEffect item. Mirroring should affect how it looks. + ShaderEffect { + x: 200 + y: 0 + width: 50 + height: 50 + property variant source: theSource + fragmentShader: " + uniform lowp sampler2D source; + varying highp vec2 qt_TexCoord0; + void main() { + gl_FragColor = texture2D(source, qt_TexCoord0); + }" + } +} diff --git a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro index 999f0cf23d..a087948f6d 100644 --- a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro +++ b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro @@ -25,5 +25,6 @@ OTHER_FILES += \ data/DisableLayer.qml \ data/SamplerNameChange.qml \ data/ItemEffect.qml \ - data/RectangleEffect.qml + data/RectangleEffect.qml \ + data/TextureMirroring.qml DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 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) |