diff options
author | Gunnar Sletta <gunnar.sletta@jollamobile.com> | 2015-01-19 19:48:23 +0100 |
---|---|---|
committer | Gunnar Sletta <gunnar@sletta.org> | 2015-03-10 16:42:45 +0000 |
commit | 95d6fbc30b180018a6f6d9a69d31b03223608e22 (patch) | |
tree | 32305af08780a5c2b2229ee3a516a55a05c00e1b | |
parent | 194df1ff60e14d01dd40c23086b8d7f257f42a41 (diff) | |
download | qtgraphicaleffects-95d6fbc30b180018a6f6d9a69d31b03223608e22.tar.gz |
Move SourceProxy to C++ and introduce "private" module.
This gives us a bit better control in terms of what we
want to check for. It should also fix some subtle bugs
when layer and ShaderEffectSource is used as input.
Change-Id: I29de13598811623c31563ac6e88f070aee0bab54
Task-number: QTBUG-40849
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
43 files changed, 766 insertions, 199 deletions
diff --git a/src/effects/Blend.qml b/src/effects/Blend.qml index d6abb33..34ed86e 100644 --- a/src/effects/Blend.qml +++ b/src/effects/Blend.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype Blend diff --git a/src/effects/BrightnessContrast.qml b/src/effects/BrightnessContrast.qml index c5eadad..f948235 100644 --- a/src/effects/BrightnessContrast.qml +++ b/src/effects/BrightnessContrast.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype BrightnessContrast diff --git a/src/effects/ColorOverlay.qml b/src/effects/ColorOverlay.qml index 1104a10..550ecc9 100644 --- a/src/effects/ColorOverlay.qml +++ b/src/effects/ColorOverlay.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype ColorOverlay diff --git a/src/effects/Colorize.qml b/src/effects/Colorize.qml index ca06452..7a95125 100644 --- a/src/effects/Colorize.qml +++ b/src/effects/Colorize.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype Colorize diff --git a/src/effects/ConicalGradient.qml b/src/effects/ConicalGradient.qml index 044fd46..c86a832 100644 --- a/src/effects/ConicalGradient.qml +++ b/src/effects/ConicalGradient.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype ConicalGradient diff --git a/src/effects/Desaturate.qml b/src/effects/Desaturate.qml index d449cf4..0f9163c 100644 --- a/src/effects/Desaturate.qml +++ b/src/effects/Desaturate.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype Desaturate diff --git a/src/effects/DirectionalBlur.qml b/src/effects/DirectionalBlur.qml index 0f57509..8f571e6 100644 --- a/src/effects/DirectionalBlur.qml +++ b/src/effects/DirectionalBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype DirectionalBlur diff --git a/src/effects/Displace.qml b/src/effects/Displace.qml index 7ad9f01..a3b57c5 100644 --- a/src/effects/Displace.qml +++ b/src/effects/Displace.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype Displace diff --git a/src/effects/DropShadow.qml b/src/effects/DropShadow.qml index dd0231d..d134e02 100644 --- a/src/effects/DropShadow.qml +++ b/src/effects/DropShadow.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype DropShadow diff --git a/src/effects/FastBlur.qml b/src/effects/FastBlur.qml index 74da4f4..adb882c 100644 --- a/src/effects/FastBlur.qml +++ b/src/effects/FastBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype FastBlur diff --git a/src/effects/GammaAdjust.qml b/src/effects/GammaAdjust.qml index 27ec5af..59f1dd8 100644 --- a/src/effects/GammaAdjust.qml +++ b/src/effects/GammaAdjust.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype GammaAdjust diff --git a/src/effects/GaussianBlur.qml b/src/effects/GaussianBlur.qml index d5922ca..8c3f0e6 100644 --- a/src/effects/GaussianBlur.qml +++ b/src/effects/GaussianBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype GaussianBlur diff --git a/src/effects/Glow.qml b/src/effects/Glow.qml index 245873b..6eca986 100644 --- a/src/effects/Glow.qml +++ b/src/effects/Glow.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype Glow diff --git a/src/effects/HueSaturation.qml b/src/effects/HueSaturation.qml index 81de6a9..b08c6bf 100644 --- a/src/effects/HueSaturation.qml +++ b/src/effects/HueSaturation.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype HueSaturation diff --git a/src/effects/InnerShadow.qml b/src/effects/InnerShadow.qml index 3981255..de59781 100644 --- a/src/effects/InnerShadow.qml +++ b/src/effects/InnerShadow.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype InnerShadow diff --git a/src/effects/LevelAdjust.qml b/src/effects/LevelAdjust.qml index 543bf0a..a209cab 100644 --- a/src/effects/LevelAdjust.qml +++ b/src/effects/LevelAdjust.qml @@ -39,7 +39,7 @@ *****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype LevelAdjust diff --git a/src/effects/LinearGradient.qml b/src/effects/LinearGradient.qml index b9d2934..5c52f6c 100644 --- a/src/effects/LinearGradient.qml +++ b/src/effects/LinearGradient.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype LinearGradient diff --git a/src/effects/MaskedBlur.qml b/src/effects/MaskedBlur.qml index adfa678..19a6810 100644 --- a/src/effects/MaskedBlur.qml +++ b/src/effects/MaskedBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype MaskedBlur diff --git a/src/effects/OpacityMask.qml b/src/effects/OpacityMask.qml index 2f33b8c..6653ddf 100644 --- a/src/effects/OpacityMask.qml +++ b/src/effects/OpacityMask.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype OpacityMask diff --git a/src/effects/RadialBlur.qml b/src/effects/RadialBlur.qml index 04f410c..e857438 100644 --- a/src/effects/RadialBlur.qml +++ b/src/effects/RadialBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype RadialBlur diff --git a/src/effects/RadialGradient.qml b/src/effects/RadialGradient.qml index afd6aff..5196ba2 100644 --- a/src/effects/RadialGradient.qml +++ b/src/effects/RadialGradient.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype RadialGradient diff --git a/src/effects/RectangularGlow.qml b/src/effects/RectangularGlow.qml index d0b89df..8ed1ac7 100644 --- a/src/effects/RectangularGlow.qml +++ b/src/effects/RectangularGlow.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype RectangularGlow diff --git a/src/effects/RecursiveBlur.qml b/src/effects/RecursiveBlur.qml index ce098bf..87c0681 100644 --- a/src/effects/RecursiveBlur.qml +++ b/src/effects/RecursiveBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype RecursiveBlur diff --git a/src/effects/ThresholdMask.qml b/src/effects/ThresholdMask.qml index cdb3c79..399e47c 100644 --- a/src/effects/ThresholdMask.qml +++ b/src/effects/ThresholdMask.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype ThresholdMask diff --git a/src/effects/ZoomBlur.qml b/src/effects/ZoomBlur.qml index df48c57..77f0f9f 100644 --- a/src/effects/ZoomBlur.qml +++ b/src/effects/ZoomBlur.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import "private" +import QtGraphicalEffects.private 1.0 /*! \qmltype ZoomBlur diff --git a/src/effects/effects.pro b/src/effects/effects.pro index 355cfff..32e6d0b 100644 --- a/src/effects/effects.pro +++ b/src/effects/effects.pro @@ -1,39 +1,3 @@ -TARGETPATH = "QtGraphicalEffects" +TEMPLATE=subdirs +SUBDIRS=effects_plugin.pro private -QML_FILES = \ - Blend.qml \ - BrightnessContrast.qml \ - ColorOverlay.qml \ - Colorize.qml \ - ConicalGradient.qml \ - Desaturate.qml \ - DirectionalBlur.qml \ - Displace.qml \ - DropShadow.qml \ - FastBlur.qml \ - GammaAdjust.qml \ - GaussianBlur.qml \ - Glow.qml \ - HueSaturation.qml \ - InnerShadow.qml \ - LevelAdjust.qml \ - LinearGradient.qml \ - MaskedBlur.qml \ - OpacityMask.qml \ - RadialBlur.qml \ - RadialGradient.qml \ - RectangularGlow.qml \ - RecursiveBlur.qml \ - ThresholdMask.qml \ - ZoomBlur.qml \ - private/FastGlow.qml \ - private/FastInnerShadow.qml \ - private/FastMaskedBlur.qml \ - private/GaussianDirectionalBlur.qml \ - private/GaussianGlow.qml \ - private/GaussianInnerShadow.qml \ - private/GaussianMaskedBlur.qml \ - private/SourceProxy.qml - -QMAKE_DOCS = $$PWD/doc/qtgraphicaleffects.qdocconf -load(qml_module) diff --git a/src/effects/effects_plugin.pro b/src/effects/effects_plugin.pro new file mode 100644 index 0000000..3494d17 --- /dev/null +++ b/src/effects/effects_plugin.pro @@ -0,0 +1,31 @@ +TARGETPATH = "QtGraphicalEffects" + +QML_FILES = \ + Blend.qml \ + BrightnessContrast.qml \ + ColorOverlay.qml \ + Colorize.qml \ + ConicalGradient.qml \ + Desaturate.qml \ + DirectionalBlur.qml \ + Displace.qml \ + DropShadow.qml \ + FastBlur.qml \ + GammaAdjust.qml \ + GaussianBlur.qml \ + Glow.qml \ + HueSaturation.qml \ + InnerShadow.qml \ + LevelAdjust.qml \ + LinearGradient.qml \ + MaskedBlur.qml \ + OpacityMask.qml \ + RadialBlur.qml \ + RadialGradient.qml \ + RectangularGlow.qml \ + RecursiveBlur.qml \ + ThresholdMask.qml \ + ZoomBlur.qml \ + +QMAKE_DOCS = $$PWD/doc/qtgraphicaleffects.qdocconf +load(qml_module) diff --git a/src/effects/private/FastGlow.qml b/src/effects/private/FastGlow.qml index d57cc58..c723619 100644 --- a/src/effects/private/FastGlow.qml +++ b/src/effects/private/FastGlow.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtGraphicalEffects.private 1.0 Item { id: rootItem diff --git a/src/effects/private/FastInnerShadow.qml b/src/effects/private/FastInnerShadow.qml index 3aaba89..ca25053 100644 --- a/src/effects/private/FastInnerShadow.qml +++ b/src/effects/private/FastInnerShadow.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtGraphicalEffects.private 1.0 Item { id: rootItem diff --git a/src/effects/private/FastMaskedBlur.qml b/src/effects/private/FastMaskedBlur.qml index 8792855..e44ee4b 100644 --- a/src/effects/private/FastMaskedBlur.qml +++ b/src/effects/private/FastMaskedBlur.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtGraphicalEffects.private 1.0 Item { id: rootItem diff --git a/src/effects/private/GaussianDirectionalBlur.qml b/src/effects/private/GaussianDirectionalBlur.qml index 89dbb00..28dc52c 100644 --- a/src/effects/private/GaussianDirectionalBlur.qml +++ b/src/effects/private/GaussianDirectionalBlur.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtGraphicalEffects.private 1.0 Item { id: rootItem diff --git a/src/effects/private/GaussianGlow.qml b/src/effects/private/GaussianGlow.qml index 35e7717..7de29a1 100644 --- a/src/effects/private/GaussianGlow.qml +++ b/src/effects/private/GaussianGlow.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtGraphicalEffects.private 1.0 Item { id: rootItem diff --git a/src/effects/private/GaussianInnerShadow.qml b/src/effects/private/GaussianInnerShadow.qml index be09edf..74c98de 100644 --- a/src/effects/private/GaussianInnerShadow.qml +++ b/src/effects/private/GaussianInnerShadow.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtGraphicalEffects.private 1.0 Item { id: rootItem diff --git a/src/effects/private/GaussianMaskedBlur.qml b/src/effects/private/GaussianMaskedBlur.qml index dedb921..0ca2c5e 100644 --- a/src/effects/private/GaussianMaskedBlur.qml +++ b/src/effects/private/GaussianMaskedBlur.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtGraphicalEffects.private 1.0 Item { id: rootItem diff --git a/src/effects/private/SourceProxy.qml b/src/effects/private/SourceProxy.qml deleted file mode 100644 index e23913d..0000000 --- a/src/effects/private/SourceProxy.qml +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Graphical Effects module. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: rootItem - property variant input - property variant output - property variant sourceRect - visible: false - - Component.onCompleted: evaluateInput() - - onInputChanged: evaluateInput() - - onSourceRectChanged: evaluateInput() - - function evaluateInput() { - if (input == undefined) { - output = input - } - else if (sourceRect != undefined && sourceRect != Qt.rect(0, 0, 0, 0) && !isQQuickShaderEffectSource(input)) { - proxySource.sourceItem = input - output = proxySource - proxySource.sourceRect = sourceRect - } - else if (isQQuickItemLayerEnabled(input)) { - output = input - } - else if ((isQQuickImage(input) && !hasTileMode(input) && !hasChildren(input))) { - output = input - } - else if (isQQuickShaderEffectSource(input)) { - output = input - } - else { - proxySource.sourceItem = input - output = proxySource - proxySource.sourceRect = Qt.rect(0, 0, 0, 0) - } - } - - function isQQuickItemLayerEnabled(item) { - if (item.hasOwnProperty("layer")) { - var l = item["layer"] - if (l.hasOwnProperty("enabled") && l["enabled"].toString() == "true") - return true - } - return false - } - - function isQQuickImage(item) { - var imageProperties = [ "fillMode", "progress", "asynchronous", "sourceSize", "status", "smooth" ] - return hasProperties(item, imageProperties) - } - - function isQQuickShaderEffectSource(item) { - var shaderEffectSourceProperties = [ "hideSource", "format", "sourceItem", "mipmap", "wrapMode", "live", "recursive", "sourceRect" ] - return hasProperties(item, shaderEffectSourceProperties) - } - - function hasProperties(item, properties) { - var counter = 0 - for (var j = 0; j < properties.length; j++) { - if (item.hasOwnProperty(properties [j])) - counter++ - } - return properties.length == counter - } - - function hasChildren(item) { - if (item.hasOwnProperty("childrenRect")) { - if (item["childrenRect"].toString() != "QRectF(0, 0, 0, 0)") - return true - else - return false - } - return false - } - - function hasTileMode(item) { - if (item.hasOwnProperty("fillMode")) { - if (item["fillMode"].toString() != "0") - return true - else - return false - } - return false - } - - ShaderEffectSource { - id: proxySource - live: rootItem.input != rootItem.output - hideSource: false - smooth: true - visible: false - } -} diff --git a/src/effects/private/plugin.cpp b/src/effects/private/plugin.cpp new file mode 100644 index 0000000..6cd9047 --- /dev/null +++ b/src/effects/private/plugin.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Graphical Effects module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QtQml/qqmlengine.h> + +#include "qgfxsourceproxy_p.h" + +QT_BEGIN_NAMESPACE + +class QtGraphicalEffectsPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QByteArray(uri) == QByteArrayLiteral("QtGraphicalEffects.private")); + qmlRegisterType<QGfxSourceProxy>(uri, 1, 0, "SourceProxy"); + } +}; + +QT_END_NAMESPACE + +#include "plugin.moc" diff --git a/src/effects/private/private.pro b/src/effects/private/private.pro new file mode 100644 index 0000000..9346b41 --- /dev/null +++ b/src/effects/private/private.pro @@ -0,0 +1,24 @@ +CXX_MODULE=qml +TARGETPATH=QtGraphicalEffects/private +TARGET = qtgraphicaleffectsprivate + +QT += quick qml +# Needed to get a hold of QQuickShaderEffectSource, QQuickImage and QQuickItemPrivate +QT += quick-private gui-private core-private qml-private + +SOURCES += plugin.cpp \ + qgfxsourceproxy.cpp + +HEADERS += \ + qgfxsourceproxy_p.h + +QML_FILES = \ + FastGlow.qml \ + FastInnerShadow.qml \ + FastMaskedBlur.qml \ + GaussianDirectionalBlur.qml \ + GaussianGlow.qml \ + GaussianInnerShadow.qml \ + GaussianMaskedBlur.qml + +load(qml_plugin) diff --git a/src/effects/private/qgfxsourceproxy.cpp b/src/effects/private/qgfxsourceproxy.cpp new file mode 100644 index 0000000..5ee9280 --- /dev/null +++ b/src/effects/private/qgfxsourceproxy.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Graphical Effects module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgfxsourceproxy_p.h" + +#include <private/qquickshadereffectsource_p.h> +#include <private/qquickitem_p.h> +#include <private/qquickimage_p.h> + +QT_BEGIN_NAMESPACE + +QGfxSourceProxy::QGfxSourceProxy(QQuickItem *parentItem) + : QQuickItem(parentItem) + , m_input(0) + , m_output(0) + , m_proxy(0) + , m_interpolation(AnyInterpolation) +{ +} + +QGfxSourceProxy::~QGfxSourceProxy() +{ + delete m_proxy; +} + +void QGfxSourceProxy::setInput(QQuickItem *input) +{ + if (m_input == input) + return; + m_input = input; + polish(); + emit inputChanged(); +} + +void QGfxSourceProxy::setOutput(QQuickItem *output) +{ + if (m_output == output) + return; + m_output = output; + emit activeChanged(); + emit outputChanged(); +} + +void QGfxSourceProxy::setSourceRect(const QRectF &sourceRect) +{ + if (m_sourceRect == sourceRect) + return; + m_sourceRect = sourceRect; + polish(); + emit sourceRectChanged(); +} + +void QGfxSourceProxy::setInterpolation(Interpolation i) +{ + if (m_interpolation == i) + return; + m_interpolation = i; + polish(); + emit interpolationChanged(); +} + + +void QGfxSourceProxy::useProxy() +{ + if (!m_proxy) + m_proxy = new QQuickShaderEffectSource(this); + m_proxy->setSourceRect(m_sourceRect); + m_proxy->setSourceItem(m_input); + m_proxy->setSmooth(true); + setOutput(m_proxy); +} + +void QGfxSourceProxy::updatePolish() +{ + QQuickItemPrivate *d = QQuickItemPrivate::get(m_input); + + if (m_input == 0) { + setOutput(0); + return; + } + + QQuickImage *image = qobject_cast<QQuickImage *>(m_input); + QQuickShaderEffectSource *shaderSource = qobject_cast<QQuickShaderEffectSource *>(m_input); + bool layered = d->extra.isAllocated() && d->extra->layer && d->extra->layer->enabled(); + + if (shaderSource) { + if ((shaderSource->sourceRect() != m_sourceRect) + || (m_interpolation == LinearInterpolation && !shaderSource->smooth()) + || (m_interpolation == NearestInterpolation && shaderSource->smooth())) + useProxy(); + else + 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())) + useProxy(); + 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 + setOutput(m_input); + + } else if (m_input->isTextureProvider() && m_input->childItems().size() == 0) { + // item is a texture provider without children, use directly... + setOutput(m_input); + + } else { + useProxy(); + } + + // Remove the proxy if it is not in use.. + if (m_proxy && m_output == m_input) { + delete m_proxy; + m_proxy = 0; + } +} + +QT_END_NAMESPACE diff --git a/src/effects/private/qgfxsourceproxy_p.h b/src/effects/private/qgfxsourceproxy_p.h new file mode 100644 index 0000000..3356dd6 --- /dev/null +++ b/src/effects/private/qgfxsourceproxy_p.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Graphical Effects module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGFXSOURCEPROXY_P_H +#define QGFXSOURCEPROXY_P_H + +#include <QtQuick/QQuickItem> + +QT_BEGIN_NAMESPACE + +class QQuickShaderEffectSource; + +class QGfxSourceProxy : public QQuickItem +{ + Q_OBJECT + + Q_PROPERTY(QQuickItem *input READ input WRITE setInput NOTIFY inputChanged) + Q_PROPERTY(QQuickItem *output READ output NOTIFY outputChanged) + Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged) + + Q_PROPERTY(bool active READ isActive NOTIFY activeChanged) + Q_PROPERTY(Interpolation interpolation READ interpolation WRITE setInterpolation NOTIFY interpolationChanged) + + Q_ENUMS(Interpolation) + +public: + enum Interpolation { + AnyInterpolation, + NearestInterpolation, + LinearInterpolation + }; + + QGfxSourceProxy(QQuickItem *item = 0); + ~QGfxSourceProxy(); + + QQuickItem *input() const { return m_input; } + void setInput(QQuickItem *input); + + QQuickItem *output() const { return m_output; } + + QRectF sourceRect() const { return m_sourceRect; } + void setSourceRect(const QRectF &sourceRect); + + bool isActive() const { return m_output && m_output != m_input; } + + void setInterpolation(Interpolation i); + Interpolation interpolation() const { return m_interpolation; } + +protected: + void updatePolish() Q_DECL_OVERRIDE; + +signals: + void inputChanged(); + void outputChanged(); + void sourceRectChanged(); + void activeChanged(); + void interpolationChanged(); + +private: + void setOutput(QQuickItem *output); + void useProxy(); + + QRectF m_sourceRect; + QQuickItem *m_input; + QQuickItem *m_output; + QQuickShaderEffectSource *m_proxy; + + Interpolation m_interpolation; +}; + +QT_END_NAMESPACE + +#endif // QGFXSOURCEPROXY_P_H diff --git a/src/effects/private/qmldir b/src/effects/private/qmldir new file mode 100644 index 0000000..e17d9bb --- /dev/null +++ b/src/effects/private/qmldir @@ -0,0 +1,9 @@ +module QtGraphicalEffects.private +plugin qtgraphicaleffectsprivate +FastGlow 1.0 FastGlow.qml +FastInnerShadow 1.0 FastInnerShadow.qml +FastMaskedBlur 1.0 FastMaskedBlur.qml +GaussianDirectionalBlur 1.0 GaussianDirectionalBlur.qml +GaussianGlow 1.0 GaussianGlow.qml +GaussianInnerShadow 1.0 GaussianInnerShadow.qml +GaussianMaskedBlur 1.0 GaussianMaskedBlur.qml diff --git a/src/effects/qmldir b/src/effects/qmldir index 1756f2f..e16013f 100644 --- a/src/effects/qmldir +++ b/src/effects/qmldir @@ -1,3 +1,4 @@ +classname QtGraphicalEffectsPlugin Blend 1.0 Blend.qml BrightnessContrast 1.0 BrightnessContrast.qml Colorize 1.0 Colorize.qml @@ -24,3 +25,4 @@ RectangularGlow 1.0 RectangularGlow.qml ThresholdMask 1.0 ThresholdMask.qml ZoomBlur 1.0 ZoomBlur.qml designersupported + diff --git a/tests/manual/SourceProxyTest.qml b/tests/manual/SourceProxyTest.qml new file mode 100644 index 0000000..e68bc35 --- /dev/null +++ b/tests/manual/SourceProxyTest.qml @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtGraphicalEffects.private 1.0 +import QtQuick 2.4 + +Rectangle { + + Rectangle { + width: parent.width + height: 1 + color: "lightsteelblue" + } + + id: root + + height: 40 + width: parent.width + + property alias proxyInterpolation: proxy.interpolation + property bool proxyPadding: false + + property string sourcing; // "layered", "shadersource", "none"; + + property bool smoothness: true + property bool padding: false + + property alias label: text.text + + + property bool expectProxy: false + + color: proxy.active ? "darkred" : "darkblue" + + Text { + id: text + color: "white" + font.pixelSize: 14 + font.bold: true + + anchors.centerIn: parent + + layer.enabled: root.sourcing == "layered" + layer.smooth: root.smoothness + layer.sourceRect: padding ? Qt.rect(-1, -1, text.width, text.height) : Qt.rect(0, 0, 0, 0); + } + + ShaderEffectSource { + id: shaderSource + sourceItem: text + smooth: root.smoothness + sourceRect: padding ? Qt.rect(-1, -1, text.width, text.height) : Qt.rect(0, 0, 0, 0); + } + + SourceProxy { + id: proxy + input: sourcing == "shadersource" ? shaderSource : text; + visible: false + sourceRect: proxyPadding ? Qt.rect(-1, -1, text.width, text.height) : Qt.rect(0, 0, 0, 0); + } + + Text { + color: "red" + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter; + rotation: 45 + text: "FAIL" + font.pixelSize: 12 + font.bold: true + visible: root.expectProxy != proxy.active + } + +} diff --git a/tests/manual/testSourceProxy.qml b/tests/manual/testSourceProxy.qml new file mode 100644 index 0000000..1ca3f95 --- /dev/null +++ b/tests/manual/testSourceProxy.qml @@ -0,0 +1,245 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Graphical Effects module. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtGraphicalEffects.private 1.0 +import QtQuick 2.4; + +Item { + id: root + + width: 400 + height: 600 + + // Text { + // text: "source: layered, padded\nproxy: expect-no-padding" + // layer.enabled: true + // layer.sourceRect: Qt.rect(-1, -1, width, height); + // font.pixelSize: 14 + // font.bold: true + // } + + Flickable { + + anchors.fill: parent + + contentWidth: root.width + contentHeight: column.height + + Column { + id: column + width: root.width + + SourceProxyTest { + label: "source: layered, padded\nproxy: expect-no-padding" + sourcing: "layered" + proxyPadding: false + padding: true + expectProxy: true + } + SourceProxyTest { + label: "source: layered, non-padded\nproxy: expect-no-padding" + sourcing: "layered" + proxyPadding: false + padding: false + expectProxy: false + } + SourceProxyTest { + label: "source: layered, padded\nproxy: expect-padding" + sourcing: "layered" + proxyPadding: true + padding: true + expectProxy: false + } + SourceProxyTest { + label: "source: layered, non-padded\nproxy: expect-padding" + sourcing: "layered" + proxyPadding: true + padding: false + expectProxy: true + } + + + SourceProxyTest { + label: "source: shadersource, padded\nproxy: expect-no-padding" + sourcing: "shadersource" + proxyPadding: false + padding: true + expectProxy: true + } + SourceProxyTest { + label: "source: shadersource, non-padded\nproxy: expect-no-padding" + sourcing: "shadersource" + proxyPadding: false + padding: false + expectProxy: false + } + SourceProxyTest { + label: "source: shadersource, padded\nproxy: expect-padding" + sourcing: "shadersource" + proxyPadding: true + padding: true + expectProxy: false + } + SourceProxyTest { + label: "source: shadersource, non-padded\nproxy: expect-padding" + sourcing: "shadersource" + proxyPadding: true + padding: false + expectProxy: true + } + + + SourceProxyTest { + label: "source: layered, non-smooth\nproxy: any-interpolation, " + sourcing: "layered" + smoothness: false + proxyInterpolation: SourceProxy.AnyInterpolation + expectProxy: false + } + SourceProxyTest { + label: "source: layered, smooth\nproxy: any-interpolation, " + sourcing: "layered" + smoothness: true + proxyInterpolation: SourceProxy.AnyInterpolation + expectProxy: false + } + SourceProxyTest { + label: "source: layered, non-smooth\nproxy: nearest-interpolation, " + sourcing: "layered" + smoothness: false + proxyInterpolation: SourceProxy.NearestInterpolation + expectProxy: false + } + SourceProxyTest { + label: "source: layered, smooth\nproxy: nearest-interpolation, " + sourcing: "layered" + smoothness: true + proxyInterpolation: SourceProxy.NearestInterpolation + expectProxy: true + } + + SourceProxyTest { + label: "source: layered, non-smooth\nproxy: linear-interpolation, " + sourcing: "layered" + smoothness: false + proxyInterpolation: SourceProxy.LinearInterpolation + expectProxy: true + } + SourceProxyTest { + label: "source: layered, smooth\nproxy: linear-interpolation, " + sourcing: "layered" + smoothness: true + proxyInterpolation: SourceProxy.LinearInterpolation + expectProxy: false + } + + + + SourceProxyTest { + label: "source: shadersource, non-smooth\nproxy: any-interpolation, " + sourcing: "shadersource" + smoothness: false + proxyInterpolation: SourceProxy.AnyInterpolation + expectProxy: false + } + SourceProxyTest { + label: "source: shadersource, smooth\nproxy: any-interpolation, " + sourcing: "shadersource" + smoothness: true + proxyInterpolation: SourceProxy.AnyInterpolation + expectProxy: false + } + + SourceProxyTest { + label: "source: shadersource, non-smooth\nproxy: nearest-interpolation, " + sourcing: "shadersource" + smoothness: false + proxyInterpolation: SourceProxy.NearestInterpolation + expectProxy: false + } + SourceProxyTest { + label: "source: shadersource, smooth\nproxy: nearest-interpolation, " + sourcing: "shadersource" + smoothness: true + proxyInterpolation: SourceProxy.NearestInterpolation + expectProxy: true + } + + SourceProxyTest { + label: "source: shadersource, non-smooth\nproxy: linear-interpolation, " + sourcing: "shadersource" + smoothness: false + proxyInterpolation: SourceProxy.LinearInterpolation + expectProxy: true + } + SourceProxyTest { + label: "source: shadersource, smooth\nproxy: linear-interpolation, " + sourcing: "shadersource" + smoothness: true + proxyInterpolation: SourceProxy.LinearInterpolation + expectProxy: false + } + + + + SourceProxyTest { + label: "source: none\nproxy: any-interpolation" + sourcing: "none" + proxyInterpolation: SourceProxy.AnyInterpolation + expectProxy: true + } + SourceProxyTest { + label: "source: none\nproxy: nearest-interpolation" + sourcing: "none" + proxyInterpolation: SourceProxy.NearestInterpolation + expectProxy: true + } + SourceProxyTest { + label: "source: none\nproxy: linear-interpolation" + sourcing: "none" + proxyInterpolation: SourceProxy.LinearInterpolation + expectProxy: true + } + + + } + + } +} |