From 64fdf70c2249c20895101a7428a9828825a00542 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 22 Jan 2015 18:53:53 +0100 Subject: Let sourceproxy auto-configure layers. In the old SourceProxy implementation, layer.enabled = true that the layer was used without a shader source in between. However, since effects like Blur and DropShadow requires updates to sourceRect and such, the effects would not work properly. Since the usecase for layers is primarily to combine it with layer.effect, we configure the layer. [ChangeLog] When applying an effect to Item::layer.effect, the effect will update the layer properties to make the effect work, such as 'smooth' to 'true' and changing 'sourceRect' to take 'transparentBorder' into account. Change-Id: Idd68b025ade46c0b84142b2afb244730bed863d2 Reviewed-by: Laszlo Agocs --- src/effects/private/qgfxsourceproxy.cpp | 23 ++++++++++------------- tests/manual/SourceProxyTest.qml | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/effects/private/qgfxsourceproxy.cpp b/src/effects/private/qgfxsourceproxy.cpp index a319e18..cdc6fc1 100644 --- a/src/effects/private/qgfxsourceproxy.cpp +++ b/src/effects/private/qgfxsourceproxy.cpp @@ -96,7 +96,7 @@ void QGfxSourceProxy::useProxy() m_proxy = new QQuickShaderEffectSource(this); m_proxy->setSourceRect(m_sourceRect); m_proxy->setSourceItem(m_input); - m_proxy->setSmooth(true); + m_proxy->setSmooth(m_interpolation != NearestInterpolation); setOutput(m_proxy); } @@ -111,23 +111,20 @@ void QGfxSourceProxy::updatePolish() QQuickImage *image = qobject_cast(m_input); QQuickShaderEffectSource *shaderSource = qobject_cast(m_input); - bool layered = d->extra.isAllocated() && d->extra->layer && d->extra->layer->enabled(); + bool layered = d->extra.isAllocated() && d->extra->transparentForPositioner; if (shaderSource) { - if ((shaderSource->sourceRect() != m_sourceRect) - || (m_interpolation == LinearInterpolation && !shaderSource->smooth()) - || (m_interpolation == NearestInterpolation && shaderSource->smooth())) - useProxy(); - else + if (layered) { + shaderSource->setSourceRect(m_sourceRect); + shaderSource->setSmooth(m_interpolation != NearestInterpolation); setOutput(m_input); - - } else if (layered) { - if ((d->extra->layer->sourceRect() != m_sourceRect) - || (m_interpolation == LinearInterpolation && !d->extra->layer->smooth()) - || (m_interpolation == NearestInterpolation && d->extra->layer->smooth())) + } else if ((shaderSource->sourceRect() != m_sourceRect) + || (m_interpolation == LinearInterpolation && !shaderSource->smooth()) + || (m_interpolation == NearestInterpolation && shaderSource->smooth())) { useProxy(); - else + } else { setOutput(m_input); + } } else if (image && image->fillMode() == QQuickImage::Stretch && m_input->childItems().size() == 0) { // item is an image with default tiling, use directly diff --git a/tests/manual/SourceProxyTest.qml b/tests/manual/SourceProxyTest.qml index e68bc35..94c948d 100644 --- a/tests/manual/SourceProxyTest.qml +++ b/tests/manual/SourceProxyTest.qml @@ -96,6 +96,20 @@ Rectangle { sourceRect: proxyPadding ? Qt.rect(-1, -1, text.width, text.height) : Qt.rect(0, 0, 0, 0); } + Text { + id: autoConfLabel; + // This will be shown when the source is a layer which has different + // attributes set than what the source proxy expects. The source proxy + // will then configure the layer. + color: "#00ff00" + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter; + text: "(configured)" + font.pixelSize: 12 + font.bold: true + visible: root.expectProxy != proxy.active && !proxy.active && root.sourcing == "layered"; + } + Text { color: "red" anchors.right: parent.right @@ -104,7 +118,7 @@ Rectangle { text: "FAIL" font.pixelSize: 12 font.bold: true - visible: root.expectProxy != proxy.active + visible: root.expectProxy != proxy.active && !autoConfLabel.visible } } -- cgit v1.2.1