Commit 5cc1870d authored by Kim Motoyoshi Kalland's avatar Kim Motoyoshi Kalland Committed by Qt by Nokia

Allow Item components to be assigned to Item.layer.effect.

Some complex effects are easier to implement as Items using
ShaderEffects internally rather than with a top-level ShaderEffect.
Auto-tests added.

Change-Id: I4b99811b87e7ca5054bf119b99207b7f5a7c666e
Reviewed-by: default avatarGunnar Sletta <gunnar.sletta@nokia.com>
parent b057ac0a
......@@ -5497,9 +5497,9 @@ void QQuickItemLayer::activateEffect()
Q_ASSERT(!m_effect);
QObject *created = m_effectComponent->create();
m_effect = qobject_cast<QQuickShaderEffect *>(created);
m_effect = qobject_cast<QQuickItem *>(created);
if (!m_effect) {
qWarning("Item: layer.effect is not a ShaderEffect.");
qWarning("Item: layer.effect is not a QML Item.");
delete created;
return;
}
......@@ -5527,7 +5527,8 @@ void QQuickItemLayer::deactivateEffect()
Holds the effect that is applied to this layer.
The effect must be a \l ShaderEffect.
The effect is typically a \l ShaderEffect component, although any \l Item component can be
assigned. The effect should have a source texture property with a name matching \l samplerName.
\sa samplerName
*/
......
......@@ -225,7 +225,7 @@ private:
QRectF m_sourceRect;
QString m_name;
QDeclarativeComponent *m_effectComponent;
QQuickShaderEffect *m_effect;
QQuickItem *m_effect;
QQuickShaderEffectSource *m_effectSource;
};
......
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
}
}
}
}
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"
}
}
......@@ -25,7 +25,9 @@ OTHER_FILES += \
data/ZOrderChange.qml \
data/ToggleLayerAndEffect.qml \
data/DisableLayer.qml \
data/SamplerNameChange.qml
data/SamplerNameChange.qml \
data/ItemEffect.qml \
data/RectangleEffect.qml
......
......@@ -86,6 +86,8 @@ private slots:
void toggleLayerAndEffect();
void disableLayer();
void changeSamplerName();
void itemEffect();
void rectangleEffect();
private:
bool m_isMesaSoftwareRasterizer;
......@@ -403,6 +405,32 @@ void tst_QQuickItemLayer::changeSamplerName()
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"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment