summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--src/effects/Blend.qml2
-rw-r--r--src/effects/BrightnessContrast.qml2
-rw-r--r--src/effects/ColorOverlay.qml2
-rw-r--r--src/effects/Colorize.qml2
-rw-r--r--src/effects/ConicalGradient.qml2
-rw-r--r--src/effects/Desaturate.qml2
-rw-r--r--src/effects/DirectionalBlur.qml2
-rw-r--r--src/effects/Displace.qml2
-rw-r--r--src/effects/DropShadow.qml214
-rw-r--r--src/effects/FastBlur.qml2
-rw-r--r--src/effects/GammaAdjust.qml2
-rw-r--r--src/effects/GaussianBlur.qml191
-rw-r--r--src/effects/Glow.qml179
-rw-r--r--src/effects/HueSaturation.qml2
-rw-r--r--src/effects/InnerShadow.qml2
-rw-r--r--src/effects/LevelAdjust.qml2
-rw-r--r--src/effects/LinearGradient.qml2
-rw-r--r--src/effects/MaskedBlur.qml167
-rw-r--r--src/effects/OpacityMask.qml2
-rw-r--r--src/effects/RadialBlur.qml2
-rw-r--r--src/effects/RadialGradient.qml2
-rw-r--r--src/effects/RectangularGlow.qml2
-rw-r--r--src/effects/RecursiveBlur.qml2
-rw-r--r--src/effects/ThresholdMask.qml2
-rw-r--r--src/effects/ZoomBlur.qml2
-rw-r--r--src/effects/doc/images/DropShadow-transparentBorder.pngbin885 -> 8932 bytes
-rw-r--r--src/effects/doc/images/Glow-transparentBorder.pngbin1000 -> 8212 bytes
-rw-r--r--src/effects/doc/images/MaskedBlur_transparentBorder1.pngbin99793 -> 0 bytes
-rw-r--r--src/effects/doc/images/MaskedBlur_transparentBorder2.pngbin105721 -> 0 bytes
-rw-r--r--src/effects/doc/snippets/DropShadow-example.qml2
-rw-r--r--src/effects/doc/snippets/DropShadow-transparentBorder-example.qml19
-rw-r--r--src/effects/doc/snippets/Glow-example.qml2
-rw-r--r--src/effects/doc/snippets/Glow-transparentBorder-example.qml23
-rw-r--r--src/effects/effects.pro40
-rw-r--r--src/effects/effects_plugin.pro31
-rw-r--r--src/effects/private/DropShadowBase.qml99
-rw-r--r--src/effects/private/FastGlow.qml1
-rw-r--r--src/effects/private/FastInnerShadow.qml1
-rw-r--r--src/effects/private/FastMaskedBlur.qml1
-rw-r--r--src/effects/private/GaussianDirectionalBlur.qml1
-rw-r--r--src/effects/private/GaussianGlow.qml1
-rw-r--r--src/effects/private/GaussianInnerShadow.qml1
-rw-r--r--src/effects/private/GaussianMaskedBlur.qml1
-rw-r--r--src/effects/private/SourceProxy.qml136
-rw-r--r--src/effects/private/plugin.cpp64
-rw-r--r--src/effects/private/private.pro27
-rw-r--r--src/effects/private/qgfxshaderbuilder.cpp378
-rw-r--r--src/effects/private/qgfxshaderbuilder_p.h59
-rw-r--r--src/effects/private/qgfxsourceproxy.cpp141
-rw-r--r--src/effects/private/qgfxsourceproxy_p.h104
-rw-r--r--src/effects/private/qmldir10
-rw-r--r--src/effects/qmldir2
-rw-r--r--tests/auto/tst_qtgraphicaleffects.cpp29
-rw-r--r--tests/manual/SourceProxyTest.qml124
-rw-r--r--tests/manual/testSourceProxy.qml245
56 files changed, 1679 insertions, 658 deletions
diff --git a/.qmake.conf b/.qmake.conf
index e543981..66a0241 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -1,3 +1,3 @@
load(qt_build_config)
-MODULE_VERSION = 5.5.1
+MODULE_VERSION = 5.6.0
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 73710dc..d0ca1df 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..e66be6c 100644
--- a/src/effects/DropShadow.qml
+++ b/src/effects/DropShadow.qml
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** 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.
@@ -39,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import "private"
+import QtGraphicalEffects.private 1.0
/*!
\qmltype DropShadow
@@ -47,18 +48,14 @@ import "private"
\since QtGraphicalEffects 1.0
\inherits QtQuick2::Item
\ingroup qtgraphicaleffects-drop-shadow
- \brief Generates a colorized and blurred shadow image of the
- source and places it behind the original, giving the impression that
- source item is raised from the background.
- By default the effect produces a high quality shadow image, thus the
- rendering speed of the shadow might not be the highest possible. The
- rendering speed is reduced especially if the shadow edges are heavily
- softened.
+ \brief Generates a soft shadow behind the source item.
- For use cases that require faster rendering speed and for which the highest
- possible visual quality is not necessary, the
- \l{DropShadow::fast}{fast} property can be set to \c true.
+ The DropShadow effect blurs the alpha channel of the input, colorizes the
+ result and places it behind the source object to create a soft shadow. The
+ shadow's color can be changed using the \l {DropShadow::color}{color}
+ property. The location of the shadow can be changed with the \l
+ horizontalOffset and \l verticalOffset properties.
\table
\header
@@ -69,6 +66,14 @@ import "private"
\li \image DropShadow_butterfly.png
\endtable
+ The soft shadow is created by blurring the image live using a gaussian
+ blur. Performing blur live is a costly operation. Fullscreen gaussian blur
+ with even a moderate number of samples will only run at 60 fps on highend
+ graphics hardware.
+
+ When the source is static, the \l cached property can be set to allocate
+ another buffer to avoid performing the blur every time it is drawn.
+
\section1 Example
The following example shows how to apply the effect.
@@ -76,7 +81,12 @@ import "private"
*/
Item {
- id: rootItem
+ id: root
+
+ DropShadowBase {
+ id: dbs
+ anchors.fill: parent
+ }
/*!
This property defines the source item that is going to be used as the
@@ -85,18 +95,26 @@ Item {
\note It is not supported to let the effect include itself, for
instance by setting source to the effect's parent.
*/
- property variant source
+ property alias source: dbs.source
/*!
+ \qmlproperty int DropShadow::radius
+
Radius defines the softness of the shadow. A larger radius causes the
edges of the shadow to appear more blurry.
- Depending on the radius value, value of the
- \l{DropShadow::samples}{samples} should be set to sufficiently large to
- ensure the visual quality.
+ The ideal blur is acheived by selecting \c samples and \c radius such
+ that \c {samples = 1 + radius * 2}, such as:
- The value ranges from 0.0 (no blur) to inf. By default, the property is
- set to \c 0.0 (no blur).
+ \table
+ \header \li Radius \li Samples
+ \row \li 0 \e{(no blur)} \li 1
+ \row \li 1 \li 3
+ \row \li 2 \li 5
+ \row \li 3 \li 7
+ \endtable
+
+ By default, the property is set to \c {floor(samples/2)}.
\table
\header
@@ -112,9 +130,9 @@ Item {
\li \b { radius: 6 }
\li \b { radius: 12 }
\row
- \li \l samples: 24
- \li \l samples: 24
- \li \l samples: 24
+ \li \l samples: 25
+ \li \l samples: 25
+ \li \l samples: 25
\row
\li \l color: #000000
\li \l color: #000000
@@ -132,9 +150,8 @@ Item {
\li \l spread: 0
\li \l spread: 0
\endtable
-
*/
- property real radius: 0.0
+ property alias radius: dbs.radius;
/*!
This property defines how many samples are taken per pixel when edge
@@ -142,19 +159,22 @@ Item {
quality, but is slower to render.
Ideally, this value should be twice as large as the highest required
- radius value, for example, if the radius is animated between 0.0 and
- 4.0, samples should be set to 8.
+ radius value plus one, such as:
- The value ranges from 0 to 32. By default, the property is set to \c 0.
-
- This property is not intended to be animated. Changing this property may
- cause the underlying OpenGL shaders to be recompiled.
+ \table
+ \header \li Radius \li Samples
+ \row \li 0 \e{(no blur)} \li 1
+ \row \li 1 \li 3
+ \row \li 2 \li 5
+ \row \li 3 \li 7
+ \endtable
- When \l{DropShadow::fast}{fast} property is set to true, this property
- has no effect.
+ By default, the property is set to \c 9.
+ This property is not intended to be animated. Changing this property will
+ cause the underlying OpenGL shaders to be recompiled.
*/
- property int samples: 0
+ property alias samples: dbs.samples
/*!
This property defines the RGBA color value which is used for the shadow.
@@ -179,9 +199,9 @@ Item {
\li \l radius: 8
\li \l radius: 8
\row
- \li \l samples: 16
- \li \l samples: 16
- \li \l samples: 16
+ \li \l samples: 17
+ \li \l samples: 17
+ \li \l samples: 17
\row
\li \l horizontalOffset: 0
\li \l horizontalOffset: 0
@@ -195,13 +215,12 @@ Item {
\li \l spread: 0
\li \l spread: 0
\endtable
-
*/
- property color color: "black"
+ property alias color: dbs.color
/*!
- \qmlproperty real QtGraphicalEffects1::DropShadow::horizontalOffset
- \qmlproperty real QtGraphicalEffects1::DropShadow::verticalOffset
+ \qmlproperty real QtGraphicalEffects::DropShadow::horizontalOffset
+ \qmlproperty real QtGraphicalEffects::DropShadow::verticalOffset
HorizontalOffset and verticalOffset properties define the offset for the
rendered shadow compared to the DropShadow item position. Often, the
@@ -232,9 +251,9 @@ Item {
\li \l radius: 4
\li \l radius: 4
\row
- \li \l samples: 8
- \li \l samples: 8
- \li \l samples: 8
+ \li \l samples: 9
+ \li \l samples: 9
+ \li \l samples: 9
\row
\li \l color: #000000
\li \l color: #000000
@@ -248,17 +267,16 @@ Item {
\li \l spread: 0
\li \l spread: 0
\endtable
-
*/
- property real horizontalOffset: 0.0
- property real verticalOffset: 0.0
+ property alias horizontalOffset: dbs.horizontalOffset
+ property alias verticalOffset: dbs.verticalOffset
/*!
This property defines how large part of the shadow color is strenghtened
near the source edges.
The value ranges from 0.0 to 1.0. By default, the property is set to \c
- 0.5.
+ 0.0.
\table
\header
@@ -278,9 +296,9 @@ Item {
\li \l radius: 8
\li \l radius: 8
\row
- \li \l samples: 16
- \li \l samples: 16
- \li \l samples: 16
+ \li \l samples: 17
+ \li \l samples: 17
+ \li \l samples: 17
\row
\li \l color: #000000
\li \l color: #000000
@@ -294,48 +312,16 @@ Item {
\li \l verticalOffset: 20
\li \l verticalOffset: 20
\endtable
-
*/
- property real spread: 0.0
+ property alias spread: dbs.spread
/*!
- This property selects the blurring algorithm that is used to produce the
- softness for the effect. Setting this to true enables fast algorithm,
- setting value to false produces higher quality result.
-
- By default, the property is set to \c false.
+ \internal
- \table
- \header
- \li Output examples with different fast values
- \li
- \li
- \row
- \li \image DropShadow_fast1.png
- \li \image DropShadow_fast2.png
- \row
- \li \b { fast: false }
- \li \b { fast: true }
- \row
- \li \l radius: 16
- \li \l radius: 16
- \row
- \li \l samples: 24
- \li \l samples: 24
- \row
- \li \l color: #000000
- \li \l color: #000000
- \row
- \li \l horizontalOffset: 0
- \li \l horizontalOffset: 0
- \row
- \li \l verticalOffset: 20
- \li \l verticalOffset: 20
- \row
- \li \l spread: 0
- \li \l spread: 0
- \endtable
+ Starting Qt 5.6, this property has no effect. It is left here
+ for source compatibility only.
+ ### Qt 6: remove
*/
property bool fast: false
@@ -350,9 +336,8 @@ Item {
properties are animated.
By default, the property is set to \c false.
-
*/
- property bool cached: false
+ property alias cached: dbs.cached
/*!
This property determines whether or not the effect has a transparent
@@ -361,59 +346,16 @@ Item {
When set to \c true, the exterior of the item is padded with a 1 pixel
wide transparent edge, making sampling outside the source texture use
transparency instead of the edge pixels. Without this property, an
- image which has opaque edges will not get a blurred edge.
+ image which has opaque edges will not get a blurred shadow.
In the image below, the Rectangle on the left has transparent borders
and has blurred edges, whereas the Rectangle on the right does not:
+ By default, this property is set to \c true.
+
\snippet DropShadow-transparentBorder-example.qml example
- \image transparentBorder.png
+ \image DropShadow-transparentBorder.png
*/
- property bool transparentBorder: false
-
- Loader {
- x: rootItem.horizontalOffset
- y: rootItem.verticalOffset
- width: parent.width
- height: parent.height
- sourceComponent: rootItem.fast ? fastGlow : gaussianGlow
- }
-
- Component {
- id: gaussianGlow
- GaussianGlow {
- anchors.fill: parent
- source: sourceProxy.output
- radius: rootItem.radius
- maximumRadius: rootItem.samples * 0.5
- color: rootItem.color
- cached: rootItem.cached
- spread: rootItem.spread
- transparentBorder: rootItem.transparentBorder
- }
- }
-
- Component {
- id: fastGlow
- FastGlow {
- anchors.fill: parent
- source: sourceProxy.output
- blur: Math.pow(rootItem.radius / 64.0, 0.4)
- color: rootItem.color
- cached: rootItem.cached
- spread: rootItem.spread
- transparentBorder: rootItem.transparentBorder
- }
- }
-
- SourceProxy {
- id: sourceProxy
- input: rootItem.source
- sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0)
- }
- ShaderEffect {
- anchors.fill: parent
- property variant source: sourceProxy.output
- }
+ property alias transparentBorder: dbs.transparentBorder
}
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..6c53717 100644
--- a/src/effects/GaussianBlur.qml
+++ b/src/effects/GaussianBlur.qml
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** 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.
@@ -39,7 +40,8 @@
****************************************************************************/
import QtQuick 2.0
-import "private"
+import QtQuick.Window 2.1
+import QtGraphicalEffects.private 1.0
/*!
\qmltype GaussianBlur
@@ -51,7 +53,7 @@ import "private"
GaussianBlur effect softens the image by blurring it with an algorithm that
uses the Gaussian function to calculate the effect. The effect produces
- higher quality than \l{QtGraphicalEffects1::FastBlur}{FastBlur}, but is
+ higher quality than \l{QtGraphicalEffects::FastBlur}{FastBlur}, but is
slower to render.
\table
@@ -68,9 +70,13 @@ import "private"
The following example shows how to apply the effect.
\snippet GaussianBlur-example.qml example
+ Performing blur live is a costly operation. Fullscreen gaussian blur
+ with even a moderate number of samples will only run at 60 fps on highend
+ graphics hardware.
+
*/
Item {
- id: rootItem
+ id: root
/*!
This property defines the source item that is going to be blurred.
@@ -85,12 +91,19 @@ Item {
affect the blurring of an individual pixel. A larger radius increases
the blur effect.
- Depending on the radius value, value of the
- \l{GaussianBlur::samples}{samples} should be set to sufficiently large
- to ensure the visual quality.
+ The ideal blur is acheived by selecting \c samples and \c radius such
+ that \c {samples = 1 + radius * 2}, such as:
+
+ \table
+ \header \li Radius \li Samples
+ \row \li 0 \e{(no blur)} \li 1
+ \row \li 1 \li 3
+ \row \li 2 \li 5
+ \row \li 3 \li 7
+ \endtable
The value ranges from 0.0 (no blur) to inf. By default, the property is
- set to \c 0.0 (no blur).
+ set to \c floor(samples / 2.0).
\table
\header
@@ -116,7 +129,7 @@ Item {
\endtable
*/
- property real radius: 0.0
+ property real radius: Math.floor(samples / 2);
/*!
This property defines how many samples are taken per pixel when blur
@@ -124,16 +137,16 @@ Item {
to render.
Ideally, this value should be twice as large as the highest required
- radius value, for example, if the radius is animated between 0.0 and
- 4.0, samples should be set to 8.
+ radius value plus 1, for example, if the radius is animated between 0.0
+ and 4.0, samples should be set to 9.
- The value ranges from 0 to 32. By default, the property is set to \c 0.
+ By default, the property is set to \c 9.
- This property is not intended to be animated. Changing this property may
+ \note This property is not intended to be animated. Changing this property may
cause the underlying OpenGL shaders to be recompiled.
*/
- property int samples: 0
+ property int samples: 9
/*!
This property is a parameter to the gaussian function that is used when
@@ -219,7 +232,6 @@ Item {
\li \l deviation: 2.7
\li \l deviation: 2.7
\endtable
-
*/
property bool transparentBorder: false
@@ -238,58 +250,125 @@ Item {
*/
property bool cached: false
+
+ // private members...
+ /*! \internal */
+ property int _paddedTexWidth: transparentBorder ? width + 2 * _kernelRadius: width;
+ /*! \internal */
+ property int _paddedTexHeight: transparentBorder ? height + 2 * _kernelRadius: height;
+ /*! \internal */
+ property int _kernelRadius: Math.max(0, samples / 2);
+ /*! \internal */
+ property int _kernelSize: _kernelRadius * 2 + 1;
+ /*! \internal */
+ property int _dpr: Screen.devicePixelRatio;
+ /*! \internal */
+ property bool _alphaOnly: false;
+ /*! \internal */
+ property var _maskSource: undefined
+
+ /*! \internal */
+ property alias _output: sourceProxy.output;
+ /*! \internal */
+ property alias _outputRect: sourceProxy.sourceRect;
+ /*! \internal */
+ property alias _color: verticalBlur.color;
+ /*! \internal */
+ property real _thickness: 0;
+
+ onSamplesChanged: _rebuildShaders();
+ on_KernelSizeChanged: _rebuildShaders();
+ onDeviationChanged: _rebuildShaders();
+ on_DprChanged: _rebuildShaders();
+ on_MaskSourceChanged: _rebuildShaders();
+ Component.onCompleted: _rebuildShaders();
+
+ /*! \internal */
+ function _rebuildShaders() {
+ if (samples < 1)
+ return;
+
+ var params = {
+ radius: _kernelRadius,
+ deviation: deviation,
+ alphaOnly: root._alphaOnly,
+ masked: _maskSource != undefined
+ }
+ var shaders = ShaderBuilder.gaussianBlur(params);
+ horizontalBlur.fragmentShader = shaders.fragmentShader;
+ horizontalBlur.vertexShader = shaders.vertexShader;
+ }
+
SourceProxy {
id: sourceProxy
- input: rootItem.source
- sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0)
+ interpolation: SourceProxy.LinearInterpolation
+ input: root.source
+ sourceRect: root.transparentBorder
+ ? Qt.rect(-root._kernelRadius, 0, root._paddedTexWidth, parent.height)
+ : Qt.rect(0, 0, 0, 0)
}
- ShaderEffectSource {
- id: cacheItem
- anchors.fill: verticalBlur
- visible: rootItem.cached
- smooth: true
- sourceItem: verticalBlur
- live: true
- hideSource: visible
+ ShaderEffect {
+ id: horizontalBlur
+ width: root.transparentBorder ? root._paddedTexWidth : root.width
+ height: root.height;
+
+ // Used by all shaders
+ property Item source: sourceProxy.output;
+ property real spread: root.radius / root._kernelRadius;
+ property var step: Qt.vector2d(1 / (root._paddedTexWidth * root._dpr), 0);
+
+ // Used by fallback shader (sampleCount exceeds number of varyings)
+ property real deviation: root.deviation
+ property real radius: root._kernelRadius
+
+ // Only in use for DropShadow and Glow
+ property color color: "white"
+ property real thickness: Math.max(0, Math.min(0.98, 1 - root._thickness * 0.98));
+
+ // Only in use for MaskedBlur
+ property var mask: root._maskSource;
+
+ layer.enabled: true
+ layer.smooth: true
+ layer.sourceRect: root.transparentBorder
+ ? Qt.rect(0, -root._kernelRadius, width, root._paddedTexHeight)
+ : Qt.rect(0, 0, 0, 0)
+ visible: false
+ blending: false
}
- GaussianDirectionalBlur {
+ ShaderEffect {
id: verticalBlur
- x: transparentBorder ? -maximumRadius - 1 : 0
- y: transparentBorder ? -maximumRadius - 1 : 0
- width: horizontalBlur.width
- height: horizontalBlur.height
-
- horizontalStep: 0.0
- verticalStep: 1.0 / parent.height
-
- source: ShaderEffectSource {
- id: horizontalBlurSource
- sourceItem: horizontalBlur
- hideSource: true
- visible: false
- smooth: true
- }
+ x: transparentBorder ? -root._kernelRadius : 0
+ y: x;
+ width: root.transparentBorder ? root._paddedTexWidth: root.width
+ height: root.transparentBorder ? root._paddedTexHeight : root.height;
+ fragmentShader: horizontalBlur.fragmentShader
+ vertexShader: horizontalBlur.vertexShader
- deviation: rootItem.deviation
- radius: rootItem.radius
- maximumRadius: rootItem.samples * 0.5
- transparentBorder: rootItem.transparentBorder
- }
+ property Item source: horizontalBlur
+ property real spread: horizontalBlur.spread
+ property var step: Qt.vector2d(0, 1 / (root._paddedTexHeight * root._dpr));
- GaussianDirectionalBlur {
- id: horizontalBlur
- width: transparentBorder ? parent.width + 2 * maximumRadius + 2 : parent.width
- height: transparentBorder ? parent.height + 2 * maximumRadius + 2 : parent.height
+ property real deviation: horizontalBlur.deviation
+ property real radius: horizontalBlur.radius
- horizontalStep: 1.0 / parent.width
- verticalStep: 0.0
+ property color color: "black"
+ property real thickness: horizontalBlur.thickness;
+
+ property var mask: horizontalBlur.mask;
+
+ visible: true
+ }
- source: sourceProxy.output
- deviation: rootItem.deviation
- radius: rootItem.radius
- maximumRadius: rootItem.samples / 2.0
- transparentBorder: rootItem.transparentBorder
+ ShaderEffectSource {
+ id: cacheItem
+ anchors.fill: verticalBlur
+ visible: root.cached
+ smooth: true
+ sourceItem: verticalBlur
+ hideSource: visible
}
+
}
diff --git a/src/effects/Glow.qml b/src/effects/Glow.qml
index 245873b..0400921 100644
--- a/src/effects/Glow.qml
+++ b/src/effects/Glow.qml
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** 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.
@@ -39,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import "private"
+import QtGraphicalEffects.private 1.0
/*!
\qmltype Glow
@@ -47,14 +48,13 @@ import "private"
\since QtGraphicalEffects 1.0
\inherits QtQuick2::Item
\ingroup qtgraphicaleffects-glow
- \brief Generates a blurred and colorized image of the source and places it
- behind the original, giving impression that the source is glowing.
+ \brief Generates a halo like glow around the source item.
- By default effect produces a high quality glow image, thus the rendering
- speed of the effect may not be the highest possible. The rendering speed is
- reduced especially if the glow edges are heavily softened. For use cases
- that require faster rendering speed and the highest possible visual quality
- is not necessary, property \l{Glow::fast}{fast} can be set to true.
+ The Glow effect blurs the alpha channel of the source and colorizes it
+ with \l {Glow::color}{color} and places it behind the source, resulting in a halo or glow
+ around the object. The quality of the blurred edge can be controlled using
+ \l samples and \l radius and the strenght of the glow can be changed using
+ \l spread.
\table
\header
@@ -65,6 +65,11 @@ import "private"
\li \image Glow_butterfly.png
\endtable
+ The glow is created by blurring the image live using a gaussian blur.
+ Performing blur live is a costly operation. Fullscreen gaussian blur with
+ even a moderate number of samples will only run at 60 fps on highend
+ graphics hardware.
+
\section1 Example
The following example shows how to apply the effect.
@@ -72,7 +77,16 @@ import "private"
*/
Item {
- id: rootItem
+ id: root
+
+ DropShadowBase {
+ id: dps
+ anchors.fill: parent
+ color: "white"
+ spread: 0.5
+ horizontalOffset: 0
+ verticalOffset: 0
+ }
/*!
This property defines the source item that is going to be used as source
@@ -81,7 +95,7 @@ Item {
\note It is not supported to let the effect include itself, for
instance by setting source to the effect's parent.
*/
- property variant source
+ property alias source: dps.source
/*!
Radius defines the softness of the glow. A larger radius causes the
@@ -90,8 +104,18 @@ Item {
Depending on the radius value, value of the \l{Glow::samples}{samples}
should be set to sufficiently large to ensure the visual quality.
- The value ranges from 0.0 (no blur) to inf. By default, the property is
- set to \c 0.0 (no blur).
+ The ideal blur is acheived by selecting \c samples and \c radius such
+ that \c {samples = 1 + radius * 2}, such as:
+
+ \table
+ \header \li Radius \li Samples
+ \row \li 0 \e{(no blur)} \li 1
+ \row \li 1 \li 3
+ \row \li 2 \li 5
+ \row \li 3 \li 7
+ \endtable
+
+ By default, the property is set to \c {floor(samples/2)}.
\table
\header
@@ -107,9 +131,9 @@ Item {
\li \b { radius: 6 }
\li \b { radius: 12 }
\row
- \li \l samples: 24
- \li \l samples: 24
- \li \l samples: 24
+ \li \l samples: 25
+ \li \l samples: 25
+ \li \l samples: 25
\row
\li \l color: #ffffff
\li \l color: #ffffff
@@ -120,7 +144,7 @@ Item {
\li \l spread: 0
\endtable
*/
- property real radius: 0.0
+ property alias radius: dps.radius
/*!
This property defines how many samples are taken per pixel when edge
@@ -128,18 +152,22 @@ Item {
quality, but is slower to render.
Ideally, this value should be twice as large as the highest required
- radius value, for example, if the radius is animated between 0.0 and
- 4.0, samples should be set to 8.
+ radius value plus one, such as:
- The value ranges from 0 to 32. By default, the property is set to \c 0.
-
- This property is not intended to be animated. Changing this property may
- cause the underlying OpenGL shaders to be recompiled.
+ \table
+ \header \li Radius \li Samples
+ \row \li 0 \e{(no blur)} \li 1
+ \row \li 1 \li 3
+ \row \li 2 \li 5
+ \row \li 3 \li 7
+ \endtable
- When \l fast property is set to true, this property has no effect.
+ By default, the property is set to \c 9.
+ This property is not intended to be animated. Changing this property will
+ cause the underlying OpenGL shaders to be recompiled.
*/
- property int samples: 0
+ property alias samples: dps.samples
/*!
This property defines how large part of the glow color is strenghtened
@@ -166,16 +194,16 @@ Item {
\li \l radius: 8
\li \l radius: 8
\row
- \li \l samples: 16
- \li \l samples: 16
- \li \l samples: 16
+ \li \l samples: 17
+ \li \l samples: 17
+ \li \l samples: 17
\row
\li \l color: #ffffff
\li \l color: #ffffff
\li \l color: #ffffff
\endtable
*/
- property real spread: 0.0
+ property alias spread: dps.spread
/*!
This property defines the RGBA color value which is used for the glow.
@@ -200,9 +228,9 @@ Item {
\li \l radius: 8
\li \l radius: 8
\row
- \li \l samples: 16
- \li \l samples: 16
- \li \l samples: 16
+ \li \l samples: 17
+ \li \l samples: 17
+ \li \l samples: 17
\row
\li \l spread: 0.5
\li \l spread: 0.5
@@ -210,39 +238,15 @@ Item {
\endtable
*/
- property color color: "white"
+ property alias color: dps.color
/*!
- This property selects the blurring algorithm that is used to produce the
- softness for the effect. Setting this to true enables fast algorithm,
- setting value to false produces higher quality result.
+ \internal
- By default, the property is set to \c false.
+ Starting Qt 5.6, this property has no effect. It is left here
+ for source compatibility only.
- \table
- \header
- \li Output examples with different fast values
- \li
- \li
- \row
- \li \image Glow_fast1.png
- \li \image Glow_fast2.png
- \row
- \li \b { fast: false }
- \li \b { fast: true }
- \row
- \li \l radius: 16
- \li \l radius: 16
- \row
- \li \l samples: 24
- \li \l samples: 24
- \row
- \li \l color: #ffffff
- \li \l color: #ffffff
- \row
- \li \l spread: 0.3
- \li \l spread: 0.3
- \endtable
+ ### Qt 6: remove
*/
property bool fast: false
@@ -260,65 +264,26 @@ Item {
By default, the property is set to \c false.
*/
- property bool cached: false
+ property alias cached: dps.cached
/*!
This property determines whether or not the effect has a transparent
border.
- When set to \c true, the exterior of the item is padded with a 1 pixel
- wide transparent edge, making sampling outside the source texture use
+ When set to \c true, the exterior of the item is padded with a
+ transparent edge, making sampling outside the source texture use
transparency instead of the edge pixels. Without this property, an
image which has opaque edges will not get a blurred edge.
+ By default, the property is set to \c true. Set it to false if the source
+ already has a transparent edge to make the blurring a tiny bit faster.
+
In the snippet below, the Rectangle on the left has transparent borders
and has blurred edges, whereas the Rectangle on the right does not.
\snippet Glow-transparentBorder-example.qml example
- \image transparentBorder.png
+ \image Glow-transparentBorder.png
*/
- property bool transparentBorder: false
-
- Loader {
- anchors.fill: parent
- sourceComponent: rootItem.fast ? fastGlow : gaussianGlow
- }
-
- Component {
- id: gaussianGlow
- GaussianGlow {
- anchors.fill: parent
- source: sourceProxy.output
- radius: rootItem.radius
- maximumRadius: rootItem.samples * 0.5
- color: rootItem.color
- cached: rootItem.cached
- spread: rootItem.spread
- transparentBorder: rootItem.transparentBorder
- }
- }
-
- Component {
- id: fastGlow
- FastGlow {
- anchors.fill: parent
- source: sourceProxy.output
- blur: Math.pow(rootItem.radius / 64.0, 0.4)
- color: rootItem.color
- cached: rootItem.cached
- spread: rootItem.spread
- transparentBorder: rootItem.transparentBorder
- }
- }
-
- SourceProxy {
- id: sourceProxy
- input: rootItem.source
- sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0)
- }
- ShaderEffect {
- anchors.fill: parent
- property variant source: sourceProxy.output
- }
+ property alias transparentBorder: dps.transparentBorder
}
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 1f6a8c4..49adab8 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..49d1bbf 100644
--- a/src/effects/MaskedBlur.qml
+++ b/src/effects/MaskedBlur.qml
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** 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.
@@ -39,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import "private"
+import QtGraphicalEffects.private 1.0
/*!
\qmltype MaskedBlur
@@ -51,12 +52,11 @@ import "private"
MaskedBlur effect softens the image by blurring it. The intensity of the
blur can be controlled for each pixel using maskSource so that some parts of
- the source are blurred more than others. By default the effect produces a
- high quality result, thus the rendering speed may not be the highest
- possible. The rendering speed is reduced especially if the
- \l{MaskedBlur::samples}{samples} is large. For use cases that require faster
- rendering speed and the highest possible visual quality is not necessary,
- property \l{MaskedBlur::fast}{fast} can be set to true.
+ the source are blurred more than others.
+
+ Performing blur live is a costly operation. Fullscreen gaussian blur
+ with even a moderate number of samples will only run at 60 fps on highend
+ graphics hardware.
\table
\header
@@ -76,7 +76,7 @@ import "private"
*/
Item {
- id: rootItem
+ id: root
/*!
This property defines the source item that is going to be blurred.
@@ -84,7 +84,7 @@ Item {
\note It is not supported to let the effect include itself, for
instance by setting source to the effect's parent.
*/
- property variant source
+ property alias source: blur.source
/*!
This property defines the item that is controlling the final intensity
@@ -97,7 +97,7 @@ Item {
blur completely. Semitransparent maskSource pixels produce blur with a
radius that is interpolated according to the pixel transparency level.
*/
- property variant maskSource
+ property alias maskSource: maskProxy.input
/*!
This property defines the distance of the neighboring pixels which
@@ -125,21 +125,13 @@ Item {
\li \b { radius: 8 }
\li \b { radius: 16 }
\row
- \li \l samples: 24
- \li \l samples: 24
- \li \l samples: 24
- \row
- \li \l transparentBorder: false
- \li \l transparentBorder: false
- \li \l transparentBorder: false
- \row
- \li \l fast: false
- \li \l fast: false
- \li \l fast: false
+ \li \l samples: 25
+ \li \l samples: 25
+ \li \l samples: 25
\endtable
*/
- property real radius: 0.0
+ property alias radius: blur.radius
/*!
This property defines how many samples are taken per pixel when blur
@@ -147,18 +139,15 @@ Item {
to render.
Ideally, this value should be twice as large as the highest required
- radius value, for example, if the radius is animated between 0.0 and
- 4.0, samples should be set to 8.
+ radius value plus 1, for example, if the radius is animated between 0.0
+ and 4.0, samples should be set to 9.
- The value ranges from 0 to 32. By default, the property is set to \c 0.
+ By default, the property is set to \c 9.
This property is not intended to be animated. Changing this property may
cause the underlying OpenGL shaders to be recompiled.
-
- When \l{MaskedBlur::fast}{fast} property is set to true, this property
- has no effect.
*/
- property int samples: 0
+ property alias samples: blur.samples
/*!
This property allows the effect output pixels to be cached in order to
@@ -173,110 +162,56 @@ Item {
By default, the property is set to \c false.
*/
- property bool cached: false
+ property alias cached: cacheItem.visible
/*!
- This property selects the blurring algorithm that is used to produce the
- blur. Setting this to true enables fast algorithm, setting value to
- false produces higher quality result.
-
- By default, the property is set to \c false.
-
- \table
- \header
- \li Output examples with different fast values
- \li
- \li
- \row
- \li \image MaskedBlur_fast1.png
- \li \image MaskedBlur_fast2.png
- \row
- \li \b { fast: false }
- \li \b { fast: true }
- \row
- \li \l radius: 16
- \li \l radius: 16
- \row
- \li \l samples: 24
- \li \l samples: 24
- \row
- \li \l transparentBorder: false
- \li \l transparentBorder: false
- \endtable
+ \internal
+ Kept for source compatibility only. Removed in Qt 5.6
+ ### Qt6: remove
*/
property bool fast: false
/*!
- This property defines the blur behavior near the edges of the item,
- where the pixel blurring is affected by the pixels outside the source
- edges.
-
- If the property is set to \c true, the pixels outside the source are
- interpreted to be transparent, which is similar to OpenGL
- clamp-to-border extension. The blur is expanded slightly outside the
- effect item area.
+ \internal
- If the property is set to \c false, the pixels outside the source are
- interpreted to contain the same color as the pixels at the edge of the
- item, which is similar to OpenGL clamp-to-edge behavior. The blur does
- not expand outside the effect item area.
+ Kept for source compatibility only. Removed in Qt 5.6
- By default, the property is set to \c false.
+ Doing transparent border on a masked source doesn't make any sense
+ as the padded exterior will have a mask alpha value of 0 which means
+ no blurring and as the padded exterior of the source is a transparent
+ pixel, the result is no pixels at all.
- \table
- \header
- \li Output examples with different transparentBorder values
- \li
- \li
- \row
- \li \image MaskedBlur_transparentBorder1.png
- \li \image MaskedBlur_transparentBorder2.png
- \row
- \li \b { transparentBorder: false }
- \li \b { transparentBorder: true }
- \row
- \li \l radius: 64
- \li \l radius: 64
- \row
- \li \l samples: 24
- \li \l samples: 24
- \row
- \li \l fast: true
- \li \l fast: true
- \endtable
+ In Qt 5.6 and before, this worked based on that the mask source
+ was scaled up to fit the padded blur target rect, which would lead
+ to inconsistent and buggy results.
+ ### Qt6: remove
*/
- property bool transparentBorder: false
+ property bool transparentBorder;
+
+ GaussianBlur {
+ id: blur
- Loader {
- id: loaderItem
+ source: root.source;
anchors.fill: parent
- sourceComponent: rootItem.fast ? fastBlur : gaussianBlur
- }
+ _maskSource: maskProxy.output;
- Component {
- id: gaussianBlur
- GaussianMaskedBlur {
- anchors.fill: parent
- source: rootItem.source
- maskSource: rootItem.maskSource
- radius: rootItem.radius
- maximumRadius: rootItem.samples * 0.5
- transparentBorder: rootItem.transparentBorder
- cached: rootItem.cached
+ SourceProxy {
+ id: maskProxy
}
}
- Component {
- id: fastBlur
- FastMaskedBlur {
- anchors.fill: parent
- source:rootItem. source
- maskSource: rootItem.maskSource
- blur: Math.pow(rootItem.radius / 64.0, 0.4)
- transparentBorder: rootItem.transparentBorder
- cached: rootItem.cached
- }
+ ShaderEffectSource {
+ id: cacheItem
+ x: -blur._kernelRadius
+ y: -blur._kernelRadius
+ width: blur.width + 2 * blur._kernelRadius
+ height: blur.height + 2 * blur._kernelRadius
+ visible: false
+ smooth: true
+ sourceRect: Qt.rect(-blur._kernelRadius, -blur._kernelRadius, width, height);
+ sourceItem: blur
+ hideSource: visible
}
}
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 b120f5f..06318ab 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/doc/images/DropShadow-transparentBorder.png b/src/effects/doc/images/DropShadow-transparentBorder.png
index bfdaebc..bb1e3b9 100644
--- a/src/effects/doc/images/DropShadow-transparentBorder.png
+++ b/src/effects/doc/images/DropShadow-transparentBorder.png
Binary files differ
diff --git a/src/effects/doc/images/Glow-transparentBorder.png b/src/effects/doc/images/Glow-transparentBorder.png
index b26aad3..58aae6c 100644
--- a/src/effects/doc/images/Glow-transparentBorder.png
+++ b/src/effects/doc/images/Glow-transparentBorder.png
Binary files differ
diff --git a/src/effects/doc/images/MaskedBlur_transparentBorder1.png b/src/effects/doc/images/MaskedBlur_transparentBorder1.png
deleted file mode 100644
index 1f2bc5d..0000000
--- a/src/effects/doc/images/MaskedBlur_transparentBorder1.png
+++ /dev/null
Binary files differ
diff --git a/src/effects/doc/images/MaskedBlur_transparentBorder2.png b/src/effects/doc/images/MaskedBlur_transparentBorder2.png
deleted file mode 100644
index d62df72..0000000
--- a/src/effects/doc/images/MaskedBlur_transparentBorder2.png
+++ /dev/null
Binary files differ
diff --git a/src/effects/doc/snippets/DropShadow-example.qml b/src/effects/doc/snippets/DropShadow-example.qml
index fa901f7..53afd50 100644
--- a/src/effects/doc/snippets/DropShadow-example.qml
+++ b/src/effects/doc/snippets/DropShadow-example.qml
@@ -63,7 +63,7 @@ Item {
horizontalOffset: 3
verticalOffset: 3
radius: 8.0
- samples: 16
+ samples: 17
color: "#80000000"
source: butterfly
}
diff --git a/src/effects/doc/snippets/DropShadow-transparentBorder-example.qml b/src/effects/doc/snippets/DropShadow-transparentBorder-example.qml
index ecbcc4e..fe05597 100644
--- a/src/effects/doc/snippets/DropShadow-transparentBorder-example.qml
+++ b/src/effects/doc/snippets/DropShadow-transparentBorder-example.qml
@@ -54,15 +54,11 @@ Rectangle {
id: normalRect
width: 60
height: 60
- color: "#444"
-
+ radius: 10
+ color: "steelblue"
layer.enabled: true
-
layer.effect: DropShadow {
- radius: 4
- samples: radius * 2
- source: normalRect
- color: Qt.rgba(0, 0, 0, 0.5)
+ transparentBorder: false
}
}
@@ -70,15 +66,10 @@ Rectangle {
id: transparentBorderRect
width: 60
height: 60
- color: "#444"
-
+ radius: 10
+ color: "steelblue"
layer.enabled: true
-
layer.effect: DropShadow {
- radius: 4
- samples: radius * 2
- source: transparentBorderRect
- color: Qt.rgba(0, 0, 0, 0.5)
transparentBorder: true
}
}
diff --git a/src/effects/doc/snippets/Glow-example.qml b/src/effects/doc/snippets/Glow-example.qml
index a7c1497..58880c6 100644
--- a/src/effects/doc/snippets/Glow-example.qml
+++ b/src/effects/doc/snippets/Glow-example.qml
@@ -62,7 +62,7 @@ Item {
Glow {
anchors.fill: butterfly
radius: 8
- samples: 16
+ samples: 17
color: "white"
source: butterfly
}
diff --git a/src/effects/doc/snippets/Glow-transparentBorder-example.qml b/src/effects/doc/snippets/Glow-transparentBorder-example.qml
index a02744d..2bfdbe2 100644
--- a/src/effects/doc/snippets/Glow-transparentBorder-example.qml
+++ b/src/effects/doc/snippets/Glow-transparentBorder-example.qml
@@ -54,15 +54,13 @@ Rectangle {
id: normalRect
width: 60
height: 60
- color: "#444"
-
+ color: "black"
+ radius: 10
layer.enabled: true
-
layer.effect: Glow {
- radius: 4
- samples: radius * 2
- source: normalRect
- color: "steelblue"
+ samples: 15
+ color: "blue"
+ transparentBorder: false
}
}
@@ -70,15 +68,12 @@ Rectangle {
id: transparentBorderRect
width: 60
height: 60
- color: "#444"
-
+ color: "black"
+ radius: 10
layer.enabled: true
-
layer.effect: Glow {
- radius: 4
- samples: radius * 2
- source: transparentBorderRect
- color: "steelblue"
+ samples: 15
+ color: "blue"
transparentBorder: true
}
}
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/DropShadowBase.qml b/src/effects/private/DropShadowBase.qml
new file mode 100644
index 0000000..8cc259c
--- /dev/null
+++ b/src/effects/private/DropShadowBase.qml
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** 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.
+**
+** $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
+import QtGraphicalEffects.private 1.0
+import QtGraphicalEffects 1.0
+
+Item {
+ id: root
+
+ property variant source
+ property int radius: samples / 2
+ property int samples: 9
+ property color color: "black"
+ property int horizontalOffset: 0
+ property int verticalOffset: 0
+ property real spread: 0.0
+ property bool cached: false
+ property bool transparentBorder: true
+
+ GaussianBlur {
+ id: blur
+ width: parent.width
+ height: parent.height
+ x: horizontalOffset
+ y: verticalOffset
+ source: root.source
+ radius: root.radius
+ samples: root.samples
+ _thickness: root.spread
+ transparentBorder: root.transparentBorder
+
+
+ _color: root.color;
+ _alphaOnly: true
+ // ignoreDevicePixelRatio: root.ignoreDevicePixelRatio
+
+ ShaderEffect {
+ x: blur._outputRect.x - parent.x
+ y: blur._outputRect.y - parent.y
+ width: transparentBorder ? blur._outputRect.width : blur.width
+ height: transparentBorder ? blur._outputRect.height : blur.height
+ property variant source: blur._output;
+ }
+
+ }
+
+ ShaderEffectSource {
+ id: cacheItem
+ x: -blur._kernelRadius + horizontalOffset
+ y: -blur._kernelRadius + verticalOffset
+ width: blur.width + 2 * blur._kernelRadius
+ height: blur.height + 2 * blur._kernelRadius
+ visible: root.cached
+ smooth: true
+ sourceRect: Qt.rect(-blur._kernelRadius, -blur._kernelRadius, width, height);
+ sourceItem: blur
+ hideSource: visible
+ }
+
+
+}
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..9fd9ca2
--- /dev/null
+++ b/src/effects/private/plugin.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** 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"
+#include "qgfxshaderbuilder_p.h"
+
+QT_BEGIN_NAMESPACE
+
+static QObject *qgfxshaderbuilder_provider(QQmlEngine *, QJSEngine *)
+{
+ return new QGfxShaderBuilder();
+}
+
+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");
+ qmlRegisterSingletonType<QGfxShaderBuilder>(uri, 1, 0, "ShaderBuilder", qgfxshaderbuilder_provider);
+ }
+};
+
+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..2260a00
--- /dev/null
+++ b/src/effects/private/private.pro
@@ -0,0 +1,27 @@
+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 \
+ qgfxshaderbuilder.cpp \
+ qgfxsourceproxy.cpp
+
+HEADERS += \
+ qgfxsourceproxy_p.h \
+ qgfxshaderbuilder_p.h
+
+QML_FILES = \
+ DropShadowBase.qml \
+ FastGlow.qml \
+ FastInnerShadow.qml \
+ FastMaskedBlur.qml \
+ GaussianDirectionalBlur.qml \
+ GaussianGlow.qml \
+ GaussianInnerShadow.qml \
+ GaussianMaskedBlur.qml
+
+load(qml_plugin)
diff --git a/src/effects/private/qgfxshaderbuilder.cpp b/src/effects/private/qgfxshaderbuilder.cpp
new file mode 100644
index 0000000..9a109b0
--- /dev/null
+++ b/src/effects/private/qgfxshaderbuilder.cpp
@@ -0,0 +1,378 @@
+/****************************************************************************
+**
+** 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 "qgfxshaderbuilder_p.h"
+
+#include <QtCore/QDebug>
+#include <QtGui/QOffscreenSurface>
+#include <QtGui/QOpenGLContext>
+#include <QtGui/QOpenGLFunctions>
+
+#include <qmath.h>
+#include <qnumeric.h>
+
+#ifndef GL_MAX_VARYING_COMPONENTS
+#define GL_MAX_VARYING_COMPONENTS 0x8B4B
+#endif
+
+#ifndef GL_MAX_VARYING_FLOATS
+#define GL_MAX_VARYING_FLOATS 0x8DFC
+#endif
+
+QGfxShaderBuilder::QGfxShaderBuilder()
+{
+ // The following code makes the assumption that an OpenGL context the GUI
+ // thread will get the same capabilities as the render thread's OpenGL
+ // context. Not 100% accurate, but it works...
+ QOpenGLContext context;
+ context.create();
+ QOffscreenSurface surface;
+ // In very odd cases, we can get incompatible configs here unless we pass the
+ // GL context's format on to the offscreen format.
+ surface.setFormat(context.format());
+ surface.create();
+ if (context.makeCurrent(&surface)) {
+ QOpenGLFunctions *gl = context.functions();
+ if (context.isOpenGLES()) {
+ gl->glGetIntegerv(GL_MAX_VARYING_VECTORS, &m_maxBlurSamples);
+ } else if (context.format().majorVersion() >= 3) {
+ int components;
+ gl->glGetIntegerv(GL_MAX_VARYING_COMPONENTS, &components);
+ m_maxBlurSamples = components / 2.0;
+ } else {
+ int floats;
+ gl->glGetIntegerv(GL_MAX_VARYING_FLOATS, &floats);
+ m_maxBlurSamples = floats / 2.0;
+ }
+ context.doneCurrent();
+ } else {
+ qDebug() << "failed to acquire GL context to resolve capabilities, using defaults..";
+ m_maxBlurSamples = 8; // minimum number of varyings in the ES 2.0 spec.
+ }
+}
+
+/*
+
+ The algorithm works like this..
+
+ For every two pixels we want to sample we take one sample between those
+ two pixels and rely on linear interpoliation to get both values at the
+ cost of one texture sample. The sample point is calculated based on the
+ gaussian weights at the two texels.
+
+ I've included the table here for future reference:
+
+ Requested Effective Actual Actual
+ Samples Radius/Kernel Samples Radius(*)
+ -------------------------------------------------
+ 0 0 / 1x1 1 0
+ 1 0 / 1x1 1 0
+ 2 1 / 3x3 2 0
+ 3 1 / 3x3 2 0
+ 4 2 / 5x5 3 1
+ 5 2 / 5x5 3 1
+ 6 3 / 7x7 4 1
+ 7 3 / 7x7 4 1
+ 8 4 / 9x9 5 2
+ 9 4 / 9x9 5 2
+ 10 5 / 11x11 6 2
+ 11 5 / 11x11 6 2
+ 12 6 / 13x13 7 3
+ 13 6 / 13x13 7 3
+ ... ... ... ...
+
+ When ActualSamples is an 'odd' nunber, sample center pixel separately:
+ EffectiveRadius: 4
+ EffectiveKernel: 9x9
+ ActualSamples: 5
+ -4 -3 -2 -1 0 +1 +2 +3 +4
+ | | | | | | | | | |
+ \ / \ / | \ / \ /
+ tL2 tL1 tC tR1 tR2
+
+ When ActualSamples is an 'even' number, sample 3 center pixels with two
+ samples:
+ EffectiveRadius: 3
+ EffectiveKernel: 7x7
+ ActualSamples: 4
+ -3 -2 -1 0 +1 +2 +3
+ | | | | | | | |
+ \ / \ / | \ /
+ tL1 tL0 tR0 tR2
+
+ From this table we have the following formulas:
+ EffectiveRadius = RequestedSamples / 2;
+ EffectiveKernel = EffectiveRadius * 2 + 1
+ ActualSamples = 1 + RequstedSamples / 2;
+ ActualRadius = RequestedSamples / 4;
+
+ (*) ActualRadius excludes the pixel pair sampled in the center
+ for even 'actual sample' counts
+*/
+
+static qreal qgfx_gaussian(qreal x, qreal d)
+{
+ return qExp(- x * x / (2 * d * d));
+}
+
+struct QGfxGaussSample
+{
+ QByteArray name;
+ qreal pos;
+ qreal weight;
+ inline void set(const QByteArray &n, qreal p, qreal w) {
+ name = n;
+ pos = p;
+ weight = w;
+ }
+};
+
+static void qgfx_declareBlurVaryings(QByteArray &shader, QGfxGaussSample *s, int samples)
+{
+ for (int i=0; i<samples; ++i) {
+ shader += "varying highp vec2 ";
+ shader += s[i].name;
+ shader += ";\n";
+ }
+}
+
+static void qgfx_buildGaussSamplePoints(QGfxGaussSample *p, int samples, int radius, qreal deviation)
+{
+
+ if ((samples % 2) == 1) {
+ p[radius].set("tC", 0, 1);
+ for (int i=0; i<radius; ++i) {
+ qreal p0 = (i + 1) * 2 - 1;
+ qreal p1 = (i + 1) * 2;
+ qreal w0 = qgfx_gaussian(p0, deviation);
+ qreal w1 = qgfx_gaussian(p1, deviation);
+ qreal w = w0 + w1;
+ qreal samplePos = (p0 * w0 + p1 * w1) / w;
+ if (qIsNaN(samplePos)) {
+ samplePos = 0;
+ w = 0;
+ }
+ p[radius - i - 1].set("tL" + QByteArray::number(i), samplePos, w);
+ p[radius + i + 1].set("tR" + QByteArray::number(i), -samplePos, w);
+ }
+ } else {
+ { // tL0
+ qreal wl = qgfx_gaussian(-1.0, deviation);
+ qreal wc = qgfx_gaussian(0.0, deviation);
+ qreal w = wl + wc;
+ p[radius].set("tL0", -1.0 * wl / w, w);
+ p[radius+1].set("tR0", 1.0, wl); // reuse wl as gauss(-1)==gauss(1);
+ }
+ for (int i=0; i<radius; ++i) {
+ qreal p0 = (i + 1) * 2;
+ qreal p1 = (i + 1) * 2 + 1;
+ qreal w0 = qgfx_gaussian(p0, deviation);
+ qreal w1 = qgfx_gaussian(p1, deviation);
+ qreal w = w0 + w1;
+ qreal samplePos = (p0 * w0 + p1 * w1) / w;
+ if (qIsNaN(samplePos)) {
+ samplePos = 0;
+ w = 0;
+ }
+ p[radius - i - 1].set("tL" + QByteArray::number(i+1), samplePos, w);
+ p[radius + i + 2].set("tR" + QByteArray::number(i+1), -samplePos, w);
+
+ }
+ }
+}
+
+QByteArray qgfx_gaussianVertexShader(QGfxGaussSample *p, int samples)
+{
+ QByteArray shader;
+ shader.reserve(1024);
+ shader += "attribute highp vec4 qt_Vertex;\n"
+ "attribute highp vec2 qt_MultiTexCoord0;\n\n"
+ "uniform highp mat4 qt_Matrix;\n"
+ "uniform highp float spread;\n"
+ "uniform highp vec2 step;\n\n";
+
+ qgfx_declareBlurVaryings(shader, p, samples);
+
+ shader += "\nvoid main() {\n"
+ " gl_Position = qt_Matrix * qt_Vertex;\n\n";
+
+ for (int i=0; i<samples; ++i) {
+ shader += " ";
+ shader += p[i].name;
+ shader += " = qt_MultiTexCoord0";
+ if (p[i].pos != 0.0) {
+ shader += " + spread * step * float(";
+ shader += QByteArray::number(p[i].pos);
+ shader += ')';
+ }
+ shader += ";\n";
+ }
+
+ shader += "}\n";
+
+ return shader;
+}
+
+
+QByteArray qgfx_gaussianFragmentShader(QGfxGaussSample *p, int samples, bool alphaOnly)
+{
+ QByteArray shader;
+ shader.reserve(1024);
+ shader += "uniform lowp sampler2D source;\n"
+ "uniform lowp float qt_Opacity;\n";
+
+ if (alphaOnly) {
+ shader += "uniform lowp vec4 color;\n"
+ "uniform lowp float thickness;\n";
+ }
+
+ shader += "\n";
+
+
+
+ qgfx_declareBlurVaryings(shader, p, samples);
+
+ shader += "\nvoid main() {\n"
+ " gl_FragColor = ";
+ if (alphaOnly)
+ shader += "mix(vec4(0), color, clamp((";
+ else
+ shader += "(";
+
+ qreal sum = 0;
+ for (int i=0; i<samples; ++i)
+ sum += p[i].weight;
+
+ for (int i=0; i<samples; ++i) {
+ shader += "\n + float(";
+ shader += QByteArray::number(p[i].weight / sum);
+ shader += ") * texture2D(source, ";
+ shader += p[i].name;
+ shader += ")";
+ if (alphaOnly)
+ shader += ".a";
+ }
+
+ shader += "\n )";
+ if (alphaOnly)
+ shader += "/thickness, 0.0, 1.0))";
+ shader += "* qt_Opacity;\n}";
+
+ return shader;
+}
+
+
+QVariantMap QGfxShaderBuilder::gaussianBlur(const QJSValue &parameters)
+{
+ int requestedRadius = qMax(0.0, parameters.property(QStringLiteral("radius")).toNumber());
+ qreal deviation = parameters.property(QStringLiteral("deviation")).toNumber();
+ bool masked = parameters.property(QStringLiteral("masked")).toBool();
+ bool alphaOnly = parameters.property(QStringLiteral("alphaOnly")).toBool();
+
+ int requestedSamples = requestedRadius * 2 + 1;
+ int samples = 1 + requestedSamples / 2;
+ int radius = requestedSamples / 4;
+
+ QVariantMap result;
+
+ if (samples > m_maxBlurSamples || masked) {
+ QByteArray fragShader;
+ if (masked)
+ fragShader += "uniform mediump sampler2D mask;\n";
+ fragShader +=
+ "uniform highp sampler2D source;\n"
+ "uniform lowp float qt_Opacity;\n"
+ "uniform mediump float spread;\n"
+ "uniform highp vec2 step;\n";
+ if (alphaOnly) {
+ fragShader += "uniform lowp vec4 color;\n"
+ "uniform lowp float thickness;\n";
+ }
+ fragShader +=
+ "\n"
+ "varying highp vec2 qt_TexCoord0;\n"
+ "\n"
+ "void main() {\n";
+ if (alphaOnly)
+ fragShader += " mediump float result = 0.0;\n";
+ else
+ fragShader += " mediump vec4 result = vec4(0);\n";
+ fragShader += " highp vec2 pixelStep = step * spread;\n";
+ if (masked)
+ fragShader += " pixelStep *= texture2D(mask, qt_TexCoord0).a;\n";
+
+ float wSum = 0;
+ for (int r=-requestedRadius; r<=requestedRadius; ++r) {
+ float w = qgfx_gaussian(r, deviation);
+ wSum += w;
+ fragShader += " result += float(";
+ fragShader += QByteArray::number(w);
+ fragShader += ") * texture2D(source, qt_TexCoord0 + pixelStep * float(";
+ fragShader += QByteArray::number(r);
+ fragShader += "))";
+ if (alphaOnly)
+ fragShader += ".a";
+ fragShader += ";\n";
+ }
+ fragShader += " const mediump float wSum = ";
+ fragShader += QByteArray::number(wSum);
+ fragShader += ";\n"
+ " gl_FragColor = ";
+ if (alphaOnly)
+ fragShader += "mix(vec4(0), color, clamp((result / wSum) / thickness, 0.0, 1.0)) * qt_Opacity;\n";
+ else
+ fragShader += "(qt_Opacity / wSum) * result;\n";
+ fragShader += "}\n";
+ result[QStringLiteral("fragmentShader")] = fragShader;
+
+ result[QStringLiteral("vertexShader")] =
+ "attribute highp vec4 qt_Vertex;\n"
+ "attribute highp vec2 qt_MultiTexCoord0;\n"
+ "uniform highp mat4 qt_Matrix;\n"
+ "varying highp vec2 qt_TexCoord0;\n"
+ "void main() {\n"
+ " gl_Position = qt_Matrix * qt_Vertex;\n"
+ " qt_TexCoord0 = qt_MultiTexCoord0;\n"
+ "}\n";
+ return result;
+ }
+
+ QVarLengthArray<QGfxGaussSample, 64> p(samples);
+ qgfx_buildGaussSamplePoints(p.data(), samples, radius, deviation);
+
+ result[QStringLiteral("fragmentShader")] = qgfx_gaussianFragmentShader(p.data(), samples, alphaOnly);
+ result[QStringLiteral("vertexShader")] = qgfx_gaussianVertexShader(p.data(), samples);
+
+ return result;
+}
+
diff --git a/src/effects/private/qgfxshaderbuilder_p.h b/src/effects/private/qgfxshaderbuilder_p.h
new file mode 100644
index 0000000..3ec993d
--- /dev/null
+++ b/src/effects/private/qgfxshaderbuilder_p.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** 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 QGFXSHADERBUILDER_P_H
+#define QGFXSHADERBUILDER_P_H
+
+#include <QtCore/QObject>
+#include <QtCore/QVariantMap>
+
+#include <QtQml/QJSValue>
+
+QT_BEGIN_NAMESPACE
+
+class QGfxShaderBuilder : public QObject
+{
+ Q_OBJECT
+
+public:
+ QGfxShaderBuilder();
+
+ Q_INVOKABLE QVariantMap gaussianBlur(const QJSValue &parameters);
+
+private:
+ int m_maxBlurSamples;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGFXSHADERBUILDER_P_H
diff --git a/src/effects/private/qgfxsourceproxy.cpp b/src/effects/private/qgfxsourceproxy.cpp
new file mode 100644
index 0000000..8f841f2
--- /dev/null
+++ b/src/effects/private/qgfxsourceproxy.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** 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(m_interpolation != NearestInterpolation);
+ setOutput(m_proxy);
+}
+
+void QGfxSourceProxy::updatePolish()
+{
+ if (m_input == 0) {
+ setOutput(0);
+ return;
+ }
+
+ QQuickItemPrivate *d = QQuickItemPrivate::get(m_input);
+ QQuickImage *image = qobject_cast<QQuickImage *>(m_input);
+ QQuickShaderEffectSource *shaderSource = qobject_cast<QQuickShaderEffectSource *>(m_input);
+ bool layered = d->extra.isAllocated() && d->extra->transparentForPositioner;
+
+ if (shaderSource) {
+ if (layered) {
+ shaderSource->setSourceRect(m_sourceRect);
+ shaderSource->setSmooth(m_interpolation != NearestInterpolation);
+ }
+ 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 (!image && 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..69d8e10
--- /dev/null
+++ b/src/effects/private/qgfxsourceproxy_p.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** 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 RESET resetInput)
+ 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);
+ void resetInput() { setInput(0); }
+
+ 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..aad4a1c
--- /dev/null
+++ b/src/effects/private/qmldir
@@ -0,0 +1,10 @@
+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
+DropShadowBase 1.0 DropShadowBase.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/auto/tst_qtgraphicaleffects.cpp b/tests/auto/tst_qtgraphicaleffects.cpp
index eebf746..c676b9c 100644
--- a/tests/auto/tst_qtgraphicaleffects.cpp
+++ b/tests/auto/tst_qtgraphicaleffects.cpp
@@ -406,13 +406,12 @@ void tst_qtgraphicaleffects::gaussianBlur()
QVERIFY(obj != 0);
// Default values
- QCOMPARE(obj->property("radius").toDouble(), 0.0);
- QCOMPARE(obj->property("samples").toInt(), 0);
+ QCOMPARE(obj->property("radius").toDouble(), 4.0);
+ QCOMPARE(obj->property("samples").toInt(), 9);
QCOMPARE(obj->property("transparentBorder").toBool(), false);
double res = obj->property("deviation").toDouble();
- QVERIFY(res < 0.3000 + 0.0001);
- QVERIFY(res > 0.3000 - 0.0001);
+ QVERIFY(res > 0.0);
QCOMPARE(obj->property("cached").toBool(), false);
@@ -436,16 +435,15 @@ void tst_qtgraphicaleffects::dropShadow()
QVERIFY(obj != 0);
// Default values
- QCOMPARE(obj->property("radius").toDouble(), 0.0);
- QCOMPARE(obj->property("samples").toInt(), 0);
+ QCOMPARE(obj->property("radius").toDouble(), 4.0);
+ QCOMPARE(obj->property("samples").toInt(), 9);
QCOMPARE(obj->property("horizontalOffset").toDouble(), 0.0);
QCOMPARE(obj->property("verticalOffset").toDouble(), 0.0);
QCOMPARE(obj->property("cached").toBool(), false);
QCOMPARE(obj->property("source").toInt(), 0);
QCOMPARE(obj->property("color").toString(), QString("#000000"));
QCOMPARE(obj->property("spread").toDouble(), 0.0);
- QCOMPARE(obj->property("transparentBorder").toBool(), false);
- QCOMPARE(obj->property("fast").toBool(), false);
+ QCOMPARE(obj->property("transparentBorder").toBool(), true);
delete obj;
}
@@ -550,13 +548,12 @@ void tst_qtgraphicaleffects::glow()
QVERIFY(obj != 0);
// Default values
- QCOMPARE(obj->property("radius").toDouble(), 0.0);
- QCOMPARE(obj->property("samples").toInt(), 0);
+ QCOMPARE(obj->property("radius").toDouble(), 4.0);
+ QCOMPARE(obj->property("samples").toInt(), 9);
QCOMPARE(obj->property("cached").toBool(), false);
- QCOMPARE(obj->property("spread").toDouble(), 0.0);
+ QCOMPARE(obj->property("spread").toDouble(), 0.5);
QCOMPARE(obj->property("color").toString(), QString("#ffffff"));
- QCOMPARE(obj->property("transparentBorder").toBool(), false);
- QCOMPARE(obj->property("fast").toBool(), false);
+ QCOMPARE(obj->property("transparentBorder").toBool(), true);
delete obj;
}
@@ -768,11 +765,9 @@ void tst_qtgraphicaleffects::maskedBlur()
// Default values
QCOMPARE(obj->property("source").toInt(), 0);
QCOMPARE(obj->property("maskSource").toInt(), 0);
- QCOMPARE(obj->property("radius").toDouble(), 0.0);
- QCOMPARE(obj->property("samples").toInt(), 0);
+ QCOMPARE(obj->property("radius").toDouble(), 4.0);
+ QCOMPARE(obj->property("samples").toInt(), 9);
QCOMPARE(obj->property("cached").toBool(), false);
- QCOMPARE(obj->property("transparentBorder").toBool(), false);
- QCOMPARE(obj->property("fast").toBool(), false);
delete obj;
}
diff --git a/tests/manual/SourceProxyTest.qml b/tests/manual/SourceProxyTest.qml
new file mode 100644
index 0000000..94c948d
--- /dev/null
+++ b/tests/manual/SourceProxyTest.qml
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** 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 {
+ 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
+ anchors.verticalCenter: parent.verticalCenter;
+ rotation: 45
+ text: "FAIL"
+ font.pixelSize: 12
+ font.bold: true
+ visible: root.expectProxy != proxy.active && !autoConfLabel.visible
+ }
+
+}
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
+ }
+
+
+ }
+
+ }
+}