summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorMarko Niemelä <marko.a.niemela@nokia.com>2011-05-25 11:19:14 (GMT)
committerMarko Niemelä <marko.a.niemela@nokia.com>2011-05-25 12:25:30 (GMT)
commitdb20b6c03b6a93ab3e483cd85d5d0a923c3d3430 (patch)
treeafbfe4daa2d8f2f6a1647f1573386a84c2b1b222 /tests/benchmarks
parent04cde562a0be446234e33725c999bdb61fab3ff2 (diff)
downloadQt-db20b6c03b6a93ab3e483cd85d5d0a923c3d3430.zip
Qt-db20b6c03b6a93ab3e483cd85d5d0a923c3d3430.tar.gz
Qt-db20b6c03b6a93ab3e483cd85d5d0a923c3d3430.tar.bz2
Backported QML ShaderEffectItem from QML2.0 into Qt Quick 1.1
This issue is about backporting Scenegraph's ShaderEffectItem and ShaderEffectSource elements into Qt Quick 1.1 as a Qt labs plugin. Purpose of these elements is to provide an interface for utilizing OpenGL shaders in QML applications. Task-number: QTBUG-18346 Reviewed-by: Kim Gronholm
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/declarative/declarative.pro2
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/GaussianBlur.qml43
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/GaussianDirectionalBlur.qml168
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/GaussianDropShadow.qml41
-rwxr-xr-xtests/benchmarks/declarative/qmlshadersplugin/TestGaussianDropShadow.qml66
-rwxr-xr-xtests/benchmarks/declarative/qmlshadersplugin/TestWater.qml20
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/Water.qml85
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/bg.jpgbin0 -> 10189 bytes
-rwxr-xr-xtests/benchmarks/declarative/qmlshadersplugin/drop_shadow_small.pngbin0 -> 46081 bytes
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/qmlshadersplugin.pro23
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/sky.jpgbin0 -> 36734 bytes
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/tst_performance.cpp110
12 files changed, 557 insertions, 1 deletions
diff --git a/tests/benchmarks/declarative/declarative.pro b/tests/benchmarks/declarative/declarative.pro
index 5dd31f3..51bbfae 100644
--- a/tests/benchmarks/declarative/declarative.pro
+++ b/tests/benchmarks/declarative/declarative.pro
@@ -10,6 +10,6 @@ SUBDIRS += \
script \
qmltime
-contains(QT_CONFIG, opengl): SUBDIRS += painting
+contains(QT_CONFIG, opengl): SUBDIRS += painting qmlshadersplugin
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/GaussianBlur.qml b/tests/benchmarks/declarative/qmlshadersplugin/GaussianBlur.qml
new file mode 100644
index 0000000..4424b0b
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/GaussianBlur.qml
@@ -0,0 +1,43 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: gaussianBlur
+ property variant source: 0
+ property real radius: 8;
+ property real deviation: Math.sqrt(-((radius+1) * (radius+1)) / (2 * Math.log(1.0 / 255.0)))
+ property bool live: true
+
+ ShaderEffectItem {
+ id: cache
+ anchors.fill: parent
+ visible: !gaussianBlur.live
+ property variant source: ShaderEffectSource { sourceItem: verticalBlur; live: false; hideSource: true }
+ }
+
+ GaussianDirectionalBlur {
+ id: verticalBlur
+ anchors.fill: parent
+
+ deltaX: 0.0
+ deltaY: 1.0/parent.height
+
+ source: ShaderEffectSource { sourceItem: horizontalBlur; hideSource: true }
+ deviation: gaussianBlur.deviation
+ radius: gaussianBlur.radius
+ }
+
+ GaussianDirectionalBlur {
+ id: horizontalBlur
+ anchors.fill: parent
+ blending: false
+
+ deltaX: 1.0/parent.width
+ deltaY: 0.0
+
+ source: gaussianBlur.source
+ deviation: gaussianBlur.deviation
+ radius: gaussianBlur.radius
+ }
+
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/GaussianDirectionalBlur.qml b/tests/benchmarks/declarative/qmlshadersplugin/GaussianDirectionalBlur.qml
new file mode 100644
index 0000000..33f576b
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/GaussianDirectionalBlur.qml
@@ -0,0 +1,168 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+// Note 1. This shader implements gaussian blur without dynamic array access from inside shader loops (Optional feature in OpenGLES 2.0).
+// Note 2. Shader code is generated to avoid ecessive if-else structure in fragment shader. Code re-generation (very slow!) happens if blur radius is changed.
+
+ShaderEffectItem {
+ id: effect
+ property variant source: 0
+ property real deviation: Math.sqrt(-((radius+1) * (radius+1)) / (2 * Math.log(1.0 / 255.0)));
+ property real radius: 8;
+ property real deltaX: 0.0
+ property real deltaY: 0.0
+
+ property real gaussianSum: 0.0
+ property real startIndex: 0.0
+ property real samples: radius * 2
+
+ property variant gwts: []
+ property variant delta: Qt.vector3d(effect.deltaX, effect.deltaY, effect.startIndex);
+ property variant factor_0_2: Qt.vector3d(effect.gwts[0], effect.gwts[1], effect.gwts[2]);
+ property variant factor_3_5: Qt.vector3d(effect.gwts[3],effect.gwts[4],effect.gwts[5]);
+ property variant factor_6_8: Qt.vector3d(effect.gwts[6],effect.gwts[7],effect.gwts[8]);
+ property variant factor_9_11: Qt.vector3d(effect.gwts[9],effect.gwts[10],effect.gwts[11]);
+ property variant factor_12_14: Qt.vector3d(effect.gwts[12],effect.gwts[13],effect.gwts[14]);
+ property variant factor_15_17: Qt.vector3d(effect.gwts[15],effect.gwts[16],effect.gwts[17]);
+ property variant factor_18_20: Qt.vector3d(effect.gwts[18],effect.gwts[19],effect.gwts[20]);
+ property variant factor_21_23: Qt.vector3d(effect.gwts[21],effect.gwts[22],effect.gwts[23]);
+ property variant factor_24_26: Qt.vector3d(effect.gwts[24],effect.gwts[25],effect.gwts[26]);
+ property variant factor_27_29: Qt.vector3d(effect.gwts[27],effect.gwts[28],effect.gwts[29]);
+ property variant factor_30_32: Qt.vector3d(effect.gwts[30],effect.gwts[31],effect.gwts[32]);
+
+ //Gaussian function = h(x):=(1/sqrt(2*3.14159*(D^2))) * %e^(-(x^2)/(2*(D^2)));
+ function gausFunc(x){
+ return (1/Math.sqrt(2*3.1415926*(Math.pow(effect.deviation,2)))) * Math.pow(2.7182818,-((Math.pow(x,2))/(2*(Math.pow(effect.deviation,2)))));
+ }
+
+ function calcGWTS() {
+ var n = new Array(Math.floor(effect.samples));
+ var step
+ for (var i = 0; i < effect.samples; i++) {
+ step = -effect.samples/2 + i + 0.5
+ n[i] = gausFunc(step);
+ }
+ return n;
+ }
+
+ function buildFragmentShader() {
+
+ var shaderSteps = [
+ "gl_FragColor += texture2D(source, texCoord) * factor_0_2.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_0_2.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_0_2.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_3_5.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_3_5.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_3_5.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_6_8.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_6_8.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_6_8.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_9_11.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_9_11.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_9_11.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_12_14.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_12_14.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_12_14.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_15_17.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_15_17.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_15_17.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_18_20.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_18_20.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_18_20.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_21_23.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_21_23.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_21_23.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_24_26.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_24_26.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_24_26.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_27_29.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_27_29.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_27_29.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_30_32.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_30_32.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_30_32.z; texCoord += shift;"
+ ]
+
+ var shader = fragmentShader_begin
+ var samples = effect.samples
+ if (samples > 32) {
+ console.log("GaussianBlur: Maximum of 32 blur samples exceeded!")
+ samples = 32
+ }
+
+ for (var i = 0; i < samples; i++) {
+ shader += shaderSteps[i]
+ }
+
+ shader += fragmentShader_end
+ effect.fragmentShader = shader
+
+ }
+
+ onDeviationChanged:{
+ effect.startIndex = -effect.samples/2 + 0.5
+ effect.gwts = calcGWTS();
+ var sum = 0.0;
+ for (var j = 0; j < effect.samples; j++) {
+ sum += effect.gwts[j];
+ }
+ effect.gaussianSum = sum
+ }
+
+ Component.onCompleted:{
+ effect.startIndex = -effect.samples/2 + 0.5
+ effect.gwts = calcGWTS();
+ var sum = 0.0;
+ for (var j = 0; j < effect.samples; j++) {
+ sum += effect.gwts[j];
+ }
+ effect.gaussianSum = sum
+ buildFragmentShader()
+ }
+
+ onSamplesChanged: {
+ buildFragmentShader()
+ }
+
+ property string fragmentShader_begin:
+ "
+ varying mediump vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ uniform highp vec3 delta;
+ uniform highp vec3 factor_0_2;
+ uniform highp vec3 factor_3_5;
+ uniform highp vec3 factor_6_8;
+ uniform highp vec3 factor_9_11;
+ uniform highp vec3 factor_12_14;
+ uniform highp vec3 factor_15_17;
+ uniform highp vec3 factor_18_20;
+ uniform highp vec3 factor_21_23;
+ uniform highp vec3 factor_24_26;
+ uniform highp vec3 factor_27_29;
+ uniform highp vec3 factor_30_32;
+ uniform highp float gaussianSum;
+
+ void main() {
+ highp vec2 shift = vec2(delta.x, delta.y);
+ highp float index = delta.z;
+ mediump vec2 texCoord = qt_TexCoord0 + (shift * index);
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
+ "
+
+ property string fragmentShader_end:
+ "
+ if (gaussianSum > 0.0)
+ gl_FragColor /= gaussianSum;
+ }
+ "
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/GaussianDropShadow.qml b/tests/benchmarks/declarative/qmlshadersplugin/GaussianDropShadow.qml
new file mode 100644
index 0000000..be78c86
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/GaussianDropShadow.qml
@@ -0,0 +1,41 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: gaussianDropShadow
+
+ property color shadowColor: Qt.rgba(0.5, 0.5, 0.5, 1.0)
+ property variant source: 0
+ property real radius: 8
+ property real deviation: Math.sqrt(-((radius+1) * (radius+1)) / (2 * Math.log(1.0 / 255.0)))
+ property bool live: true
+
+ GaussianBlur {
+ id: blur
+ anchors.fill: parent
+ radius: gaussianDropShadow.radius
+ deviation: gaussianDropShadow.deviation
+ source: gaussianDropShadow.source
+ live: gaussianDropShadow.live
+ }
+
+ ShaderEffectItem {
+ id: shadow
+ property color shadowColor: gaussianDropShadow.shadowColor
+ property variant source: ShaderEffectSource { sourceItem: blur; hideSource: true }
+ anchors.fill: parent
+
+ fragmentShader:
+ "
+ varying mediump vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ uniform lowp vec4 shadowColor;
+
+ void main() {
+ lowp vec4 sourceColor = texture2D(source, qt_TexCoord0);
+ gl_FragColor = mix(vec4(0), shadowColor, sourceColor.a);
+ }
+ "
+ }
+}
+
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/TestGaussianDropShadow.qml b/tests/benchmarks/declarative/qmlshadersplugin/TestGaussianDropShadow.qml
new file mode 100755
index 0000000..5843d55
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/TestGaussianDropShadow.qml
@@ -0,0 +1,66 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: main
+ width: 360
+ height: 640
+
+ property bool liveShadows: true
+ property real r: 0
+
+ NumberAnimation on r {
+ loops: Animation.Infinite
+ from: 0
+ to: 360
+ duration: 3000
+ }
+
+ Image {
+ id: background
+ width: main.width
+ height: main.height
+ fillMode: Image.Tile
+ source: "bg.jpg"
+ }
+
+ GaussianDropShadow {
+ x: image1.x + 50
+ y: image1.y + 50
+ width: image1.width
+ height: image1.height
+ shadowColor: "#88000000"
+ source: ShaderEffectSource { sourceItem: image1; hideSource: false; sourceRect: Qt.rect(-10, -10, image1.width + 20, image1.height + 20) }
+ radius: 12.0
+ deviation: 12
+ rotation: r
+ }
+
+ Image {
+ id: image1
+ anchors.fill: parent
+ source: "drop_shadow_small.png"
+ smooth: true
+ rotation: r
+ }
+
+ GaussianDropShadow {
+ x: image2.x + 50
+ y: image2.y + 50
+ width: image2.width
+ height: image2.height
+ shadowColor: "#88000000"
+ source: ShaderEffectSource { sourceItem: image2; hideSource: false; sourceRect: Qt.rect(-10, -10, image2.width + 20, image2.height + 20) }
+ radius: 12.0
+ deviation: 12
+ rotation: -r
+ }
+
+ Image {
+ id: image2
+ anchors.fill: parent
+ source: "drop_shadow_small.png"
+ smooth: true
+ rotation: -r
+ }
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/TestWater.qml b/tests/benchmarks/declarative/qmlshadersplugin/TestWater.qml
new file mode 100755
index 0000000..4d90950
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/TestWater.qml
@@ -0,0 +1,20 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ width: 360
+ height: 640
+
+ Image {
+ id: image
+ width: parent.width
+ height: parent.height * 0.65
+ source: "sky.jpg"
+ smooth: true
+ }
+ Water {
+ sourceItem: image
+ intensity: 5
+ height: parent.height - image.height
+ }
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/Water.qml b/tests/benchmarks/declarative/qmlshadersplugin/Water.qml
new file mode 100644
index 0000000..02486dd
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/Water.qml
@@ -0,0 +1,85 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: root
+ property alias sourceItem: effectsource.sourceItem
+ property real intensity: 1
+ property bool waving: true
+ anchors.top: sourceItem.bottom
+ width: sourceItem.width
+ height: sourceItem.height
+
+ ShaderEffectItem {
+ anchors.fill: parent
+ property variant source: effectsource
+ property real f: 0
+ property real f2: 0
+ property alias intensity: root.intensity
+ smooth: true
+
+ ShaderEffectSource {
+ id: effectsource
+ hideSource: false
+ smooth: true
+ }
+
+ fragmentShader:
+ "
+ varying highp vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ uniform lowp float qt_Opacity;
+ uniform highp float f;
+ uniform highp float f2;
+ uniform highp float intensity;
+
+ void main() {
+ const highp float twopi = 3.141592653589 * 2.0;
+
+ highp float distanceFactorToPhase = pow(qt_TexCoord0.y + 0.5, 8.0) * 5.0;
+ highp float ofx = sin(f * twopi + distanceFactorToPhase) / 100.0;
+ highp float ofy = sin(f2 * twopi + distanceFactorToPhase * qt_TexCoord0.x) / 60.0;
+
+ highp float intensityDampingFactor = (qt_TexCoord0.x + 0.1) * (qt_TexCoord0.y + 0.2);
+ highp float distanceFactor = (1.0 - qt_TexCoord0.y) * 4.0 * intensity * intensityDampingFactor;
+
+ ofx *= distanceFactor;
+ ofy *= distanceFactor;
+
+ highp float x = qt_TexCoord0.x + ofx;
+ highp float y = 1.0 - qt_TexCoord0.y + ofy;
+
+ highp float fake = (sin((ofy + ofx) * twopi) + 0.5) * 0.05 * (1.2 - qt_TexCoord0.y) * intensity * intensityDampingFactor;
+
+ highp vec4 pix =
+ texture2D(source, vec2(x, y)) * 0.6 +
+ texture2D(source, vec2(x-fake, y)) * 0.15 +
+ texture2D(source, vec2(x, y-fake)) * 0.15 +
+ texture2D(source, vec2(x+fake, y)) * 0.15 +
+ texture2D(source, vec2(x, y+fake)) * 0.15;
+
+ highp float darken = 0.6 - (ofx - ofy) / 2.0;
+ pix.b *= 1.2 * darken;
+ pix.r *= 0.9 * darken;
+ pix.g *= darken;
+
+ gl_FragColor = qt_Opacity * vec4(pix.r, pix.g, pix.b, 1.0);
+ }
+ "
+
+ NumberAnimation on f {
+ running: root.waving
+ loops: Animation.Infinite
+ from: 0
+ to: 1
+ duration: 2410
+ }
+ NumberAnimation on f2 {
+ running: root.waving
+ loops: Animation.Infinite
+ from: 0
+ to: 1
+ duration: 1754
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/bg.jpg b/tests/benchmarks/declarative/qmlshadersplugin/bg.jpg
new file mode 100644
index 0000000..4d22143
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/bg.jpg
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/drop_shadow_small.png b/tests/benchmarks/declarative/qmlshadersplugin/drop_shadow_small.png
new file mode 100755
index 0000000..4a9b283
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/drop_shadow_small.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/qmlshadersplugin.pro b/tests/benchmarks/declarative/qmlshadersplugin/qmlshadersplugin.pro
new file mode 100644
index 0000000..9fb8852
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/qmlshadersplugin.pro
@@ -0,0 +1,23 @@
+QT += opengl declarative testlib
+
+TARGET = tst_performance
+
+SOURCES += \
+ tst_performance.cpp \
+ ../../../../src/imports/shaders/src/shadereffectitem.cpp \
+ ../../../../src/imports/shaders/src/shadereffectsource.cpp \
+ ../../../../src/imports/shaders/src/shadereffect.cpp \
+ ../../../../src/imports/shaders/src/shadereffectbuffer.cpp \
+ ../../../../src/imports/shaders/src/scenegraph/qsggeometry.cpp
+
+HEADERS += \
+ ../../../../src/imports/shaders/src/shadereffectitem.h \
+ ../../../../src/imports/shaders/src/shadereffectsource.h \
+ ../../../../src/imports/shaders/src/shadereffect.h \
+ ../../../../src/imports/shaders/src/shadereffectbuffer.h \
+ ../../../../src/imports/shaders/src/scenegraph/qsggeometry.h
+
+OTHER_FILES += \
+ *.qml \
+ *.png \
+ *.jpg
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/sky.jpg b/tests/benchmarks/declarative/qmlshadersplugin/sky.jpg
new file mode 100644
index 0000000..8fc19ed
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/sky.jpg
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/tst_performance.cpp b/tests/benchmarks/declarative/qmlshadersplugin/tst_performance.cpp
new file mode 100644
index 0000000..6ee6979
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/tst_performance.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/qtest.h>
+#include <QtDeclarative>
+#include "../../../../src/imports/shaders/src/shadereffectitem.h"
+#include "../../../../src/imports/shaders/src/shadereffectsource.h"
+//#include "../../../src/shadereffect.h"
+
+class BenchmarkItem : public QDeclarativeItem
+{
+ Q_OBJECT
+
+public:
+ BenchmarkItem( QDeclarativeItem * parent = 0 ) : QDeclarativeItem(parent)
+ , m_frameCount(0)
+ {
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+ }
+
+ void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+ QDeclarativeItem::paint(painter, option, widget);
+ if (timer.restart() > 7) m_frameCount++;
+ }
+
+ int frameCount() { return m_frameCount; }
+
+private:
+ int m_frameCount;
+ QTime timer;
+};
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QDeclarativeView view;
+ view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+ view.setAttribute(Qt::WA_OpaquePaintEvent);
+ view.setAttribute(Qt::WA_NoSystemBackground);
+ view.setResizeMode(QDeclarativeView::SizeViewToRootObject);
+
+ qmlRegisterType<ShaderEffectItem>("Qt.labs.shaders", 1, 0, "ShaderEffectItem");
+ qmlRegisterType<ShaderEffectSource>("Qt.labs.shaders", 1, 0, "ShaderEffectSource");
+
+ QGLFormat format = QGLFormat::defaultFormat();
+ format.setSampleBuffers(false);
+ format.setSwapInterval(1);
+
+ QGLWidget* glWidget = new QGLWidget(format);
+ glWidget->setAutoFillBackground(false);
+ view.setViewport(glWidget);
+ view.show();
+
+ view.setSource(QUrl::fromLocalFile("TestWater.qml"));
+ BenchmarkItem *benchmarkItem;
+
+ qDebug() << "Sea Water benchmark:";
+ benchmarkItem = new BenchmarkItem(dynamic_cast<QDeclarativeItem *>(view.rootObject()));
+ QTest::qWait(5000);
+ qDebug() << "Rendered " << benchmarkItem->frameCount() << " frames in 5 seconds";
+ qDebug() << "Average " << benchmarkItem->frameCount() / 5.0 << " frames per second";
+
+ qDebug() << "Gaussian drop shadow benchmark:";
+ view.setSource(QUrl::fromLocalFile("TestGaussianDropShadow.qml"));
+ benchmarkItem = new BenchmarkItem(dynamic_cast<QDeclarativeItem *>(view.rootObject()));
+ QTest::qWait(5000);
+ qDebug() << "Rendered " << benchmarkItem->frameCount() << " frames in 5 seconds";
+ qDebug() << "Average " << benchmarkItem->frameCount() / 5.0 << " frames per second";
+}
+
+#include "tst_performance.moc"