summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/gui/animation
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/gui/animation')
-rw-r--r--tests/benchmarks/gui/animation/animation.pro2
-rw-r--r--tests/benchmarks/gui/animation/qanimation/dummyanimation.cpp61
-rw-r--r--tests/benchmarks/gui/animation/qanimation/dummyanimation.h60
-rw-r--r--tests/benchmarks/gui/animation/qanimation/dummyobject.cpp66
-rw-r--r--tests/benchmarks/gui/animation/qanimation/dummyobject.h64
-rw-r--r--tests/benchmarks/gui/animation/qanimation/main.cpp191
-rw-r--r--tests/benchmarks/gui/animation/qanimation/qanimation.pro18
-rw-r--r--tests/benchmarks/gui/animation/qanimation/rectanimation.cpp94
-rw-r--r--tests/benchmarks/gui/animation/qanimation/rectanimation.h70
9 files changed, 626 insertions, 0 deletions
diff --git a/tests/benchmarks/gui/animation/animation.pro b/tests/benchmarks/gui/animation/animation.pro
new file mode 100644
index 0000000000..a4ba273fec
--- /dev/null
+++ b/tests/benchmarks/gui/animation/animation.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS = qanimation
diff --git a/tests/benchmarks/gui/animation/qanimation/dummyanimation.cpp b/tests/benchmarks/gui/animation/qanimation/dummyanimation.cpp
new file mode 100644
index 0000000000..138ec45df9
--- /dev/null
+++ b/tests/benchmarks/gui/animation/qanimation/dummyanimation.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 test suite module 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 "dummyanimation.h"
+#include "dummyobject.h"
+
+
+DummyAnimation::DummyAnimation(DummyObject *d) : m_dummy(d)
+{
+}
+
+void DummyAnimation::updateCurrentValue(const QVariant &value)
+{
+ if (state() == Stopped)
+ return;
+ if (m_dummy)
+ m_dummy->setRect(value.toRect());
+}
+
+void DummyAnimation::updateState(State state)
+{
+ Q_UNUSED(state);
+}
diff --git a/tests/benchmarks/gui/animation/qanimation/dummyanimation.h b/tests/benchmarks/gui/animation/qanimation/dummyanimation.h
new file mode 100644
index 0000000000..73f491bcb7
--- /dev/null
+++ b/tests/benchmarks/gui/animation/qanimation/dummyanimation.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** 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 test suite 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 <QtGui>
+
+#ifndef _DUMMYANIMATION_H__
+
+class DummyObject;
+
+class DummyAnimation : public QVariantAnimation
+{
+public:
+ DummyAnimation(DummyObject *d);
+
+ void updateCurrentValue(const QVariant &value);
+ void updateState(State state);
+
+private:
+ DummyObject *m_dummy;
+};
+
+#endif
diff --git a/tests/benchmarks/gui/animation/qanimation/dummyobject.cpp b/tests/benchmarks/gui/animation/qanimation/dummyobject.cpp
new file mode 100644
index 0000000000..9178ceff6c
--- /dev/null
+++ b/tests/benchmarks/gui/animation/qanimation/dummyobject.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** 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 QtGui module 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 "dummyobject.h"
+
+DummyObject::DummyObject()
+{
+}
+
+QRect DummyObject::rect() const
+{
+ return m_rect;
+}
+
+void DummyObject::setRect(const QRect &r)
+{
+ m_rect = r;
+}
+
+float DummyObject::opacity() const
+{
+ return m_opacity;
+}
+
+void DummyObject::setOpacity(float o)
+{
+ m_opacity = o;
+}
diff --git a/tests/benchmarks/gui/animation/qanimation/dummyobject.h b/tests/benchmarks/gui/animation/qanimation/dummyobject.h
new file mode 100644
index 0000000000..81f6b8ef82
--- /dev/null
+++ b/tests/benchmarks/gui/animation/qanimation/dummyobject.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** 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 test suite 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 <QtGui>
+
+#ifndef _DUMMYOBJECT_H__
+
+class DummyObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QRect rect READ rect WRITE setRect)
+ Q_PROPERTY(float opacity READ opacity WRITE setOpacity)
+public:
+ DummyObject();
+ QRect rect() const;
+ void setRect(const QRect &r);
+ float opacity() const;
+ void setOpacity(float);
+
+private:
+ QRect m_rect;
+ float m_opacity;
+};
+
+
+#endif
diff --git a/tests/benchmarks/gui/animation/qanimation/main.cpp b/tests/benchmarks/gui/animation/qanimation/main.cpp
new file mode 100644
index 0000000000..b203949ed5
--- /dev/null
+++ b/tests/benchmarks/gui/animation/qanimation/main.cpp
@@ -0,0 +1,191 @@
+/****************************************************************************
+**
+** 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 test suite module 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 <QtGui>
+#include <qtest.h>
+
+#include "dummyobject.h"
+#include "dummyanimation.h"
+#include "rectanimation.h"
+
+#define ITERATION_COUNT 10e3
+
+class tst_qanimation : public QObject
+{
+ Q_OBJECT
+private slots:
+ void itemPropertyAnimation();
+ void itemPropertyAnimation_data() { data();}
+ void dummyAnimation();
+ void dummyAnimation_data() { data();}
+ void dummyPropertyAnimation();
+ void dummyPropertyAnimation_data() { data();}
+ void rectAnimation();
+ void rectAnimation_data() { data();}
+
+ void floatAnimation_data() { data(); }
+ void floatAnimation();
+
+private:
+ void data();
+};
+
+
+void tst_qanimation::data()
+{
+ QTest::addColumn<bool>("started");
+ QTest::newRow("NotRunning") << false;
+ QTest::newRow("Running") << true;
+}
+
+void tst_qanimation::itemPropertyAnimation()
+{
+ QFETCH(bool, started);
+ QGraphicsWidget item;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&item, "pos");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QPointF(0,0));
+ anim.setEndValue(QPointF(ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+
+}
+
+void tst_qanimation::dummyAnimation()
+{
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //first the dummy animation
+ {
+ DummyAnimation anim(&dummy);
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < anim.duration(); ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::dummyPropertyAnimation()
+{
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&dummy, "rect");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::rectAnimation()
+{
+ //this is the simplest animation you can do
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ RectAnimation anim(&dummy);
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::floatAnimation()
+{
+ //this is the simplest animation you can do
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&dummy, "opacity");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(0.f);
+ anim.setEndValue(1.f);
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+
+
+QTEST_MAIN(tst_qanimation)
+
+#include "main.moc"
diff --git a/tests/benchmarks/gui/animation/qanimation/qanimation.pro b/tests/benchmarks/gui/animation/qanimation/qanimation.pro
new file mode 100644
index 0000000000..53a139a660
--- /dev/null
+++ b/tests/benchmarks/gui/animation/qanimation/qanimation.pro
@@ -0,0 +1,18 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qanimation
+DEPENDPATH += .
+INCLUDEPATH += .
+
+CONFIG += release
+#CONFIG += debug
+
+
+SOURCES += main.cpp \
+ dummyobject.cpp \
+ dummyanimation.cpp \
+ rectanimation.cpp
+
+HEADERS += dummyobject.h \
+ dummyanimation.h \
+ rectanimation.h
diff --git a/tests/benchmarks/gui/animation/qanimation/rectanimation.cpp b/tests/benchmarks/gui/animation/qanimation/rectanimation.cpp
new file mode 100644
index 0000000000..b8082cda33
--- /dev/null
+++ b/tests/benchmarks/gui/animation/qanimation/rectanimation.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** 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 test suite module 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 "rectanimation.h"
+#include "dummyobject.h"
+
+static inline int interpolateInteger(int from, int to, qreal progress)
+{
+ return from + (to - from) * progress;
+}
+
+
+RectAnimation::RectAnimation(DummyObject *obj) : m_object(obj), m_dura(250)
+{
+}
+
+void RectAnimation::setEndValue(const QRect &rect)
+{
+ m_end = rect;
+}
+
+void RectAnimation::setStartValue(const QRect &rect)
+{
+ m_start = rect;
+}
+
+void RectAnimation::setDuration(int d)
+{
+ m_dura = d;
+}
+
+int RectAnimation::duration() const
+{
+ return m_dura;
+}
+
+
+void RectAnimation::updateCurrentTime(int currentTime)
+{
+ qreal progress = m_easing.valueForProgress( currentTime / qreal(m_dura) );
+ QRect now;
+ now.setCoords(interpolateInteger(m_start.left(), m_end.left(), progress),
+ interpolateInteger(m_start.top(), m_end.top(), progress),
+ interpolateInteger(m_start.right(), m_end.right(), progress),
+ interpolateInteger(m_start.bottom(), m_end.bottom(), progress));
+
+ bool changed = (now != m_current);
+ if (changed)
+ m_current = now;
+
+ if (state() == Stopped)
+ return;
+
+ if (m_object)
+ m_object->setRect(m_current);
+}
diff --git a/tests/benchmarks/gui/animation/qanimation/rectanimation.h b/tests/benchmarks/gui/animation/qanimation/rectanimation.h
new file mode 100644
index 0000000000..9efb91b274
--- /dev/null
+++ b/tests/benchmarks/gui/animation/qanimation/rectanimation.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 test suite 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 <QtGui>
+
+#ifndef _RECTANIMATION_H__
+
+class DummyObject;
+
+//this class is even simpler than the dummy
+//and uses no QVariant at all
+class RectAnimation : public QAbstractAnimation
+{
+public:
+ RectAnimation(DummyObject *obj);
+
+ void setEndValue(const QRect &rect);
+ void setStartValue(const QRect &rect);
+
+ void setDuration(int d);
+ int duration() const;
+
+ virtual void updateCurrentTime(int currentTime);
+
+private:
+ DummyObject *m_object;
+ QEasingCurve m_easing;
+ QRect m_start, m_end, m_current;
+ int m_dura;
+};
+
+#endif