diff options
Diffstat (limited to 'src/effects/private')
-rw-r--r-- | src/effects/private/FastGlow.qml | 1 | ||||
-rw-r--r-- | src/effects/private/FastInnerShadow.qml | 1 | ||||
-rw-r--r-- | src/effects/private/FastMaskedBlur.qml | 1 | ||||
-rw-r--r-- | src/effects/private/GaussianDirectionalBlur.qml | 1 | ||||
-rw-r--r-- | src/effects/private/GaussianGlow.qml | 1 | ||||
-rw-r--r-- | src/effects/private/GaussianInnerShadow.qml | 1 | ||||
-rw-r--r-- | src/effects/private/GaussianMaskedBlur.qml | 1 | ||||
-rw-r--r-- | src/effects/private/SourceProxy.qml | 136 | ||||
-rw-r--r-- | src/effects/private/plugin.cpp | 57 | ||||
-rw-r--r-- | src/effects/private/private.pro | 24 | ||||
-rw-r--r-- | src/effects/private/qgfxsourceproxy.cpp | 151 | ||||
-rw-r--r-- | src/effects/private/qgfxsourceproxy_p.h | 103 | ||||
-rw-r--r-- | src/effects/private/qmldir | 9 |
13 files changed, 351 insertions, 136 deletions
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 |