summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/painting/qpaintbuffer.cpp114
-rw-r--r--src/gui/painting/qpaintbuffer_p.h5
-rw-r--r--src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp9
-rw-r--r--src/testlib/qbenchmark.cpp2
-rw-r--r--tests/auto/qgl_threads/tst_openglthreading.cpp64
-rw-r--r--tests/auto/qgl_threads/tst_openglthreading.pro9
-rw-r--r--tests/benchmarks/gui/painting/painting.pro3
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/qtracebench.pro10
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc10
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/traces/basicdrawing.tracebin0 -> 366739 bytes
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/traces/creator.tracebin0 -> 541031 bytes
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/traces/qmlphoneconcept.tracebin0 -> 337439 bytes
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/traces/qmlsamegame.tracebin0 -> 246423 bytes
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/traces/textedit.tracebin0 -> 60042 bytes
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/traces/webkit.tracebin0 -> 451391 bytes
-rw-r--r--tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp262
-rw-r--r--tools/qttracereplay/main.cpp84
17 files changed, 522 insertions, 50 deletions
diff --git a/src/gui/painting/qpaintbuffer.cpp b/src/gui/painting/qpaintbuffer.cpp
index 664d864..39b76c8 100644
--- a/src/gui/painting/qpaintbuffer.cpp
+++ b/src/gui/painting/qpaintbuffer.cpp
@@ -308,6 +308,8 @@ public:
Q_Q(QPaintBufferEngine);
q->buffer->addCommand(QPaintBufferPrivate::Cmd_SystemStateChanged, QVariant(systemClip));
}
+
+ QTransform last;
};
@@ -494,6 +496,32 @@ void QPaintBufferEngine::renderHintsChanged()
void QPaintBufferEngine::transformChanged()
{
+ Q_D(QPaintBufferEngine);
+ const QTransform &transform = state()->matrix;
+
+ QTransform delta;
+
+ bool invertible = false;
+ if (transform.type() <= QTransform::TxScale && transform.type() == d->last.type())
+ delta = transform * d->last.inverted(&invertible);
+
+ d->last = transform;
+
+ if (invertible && delta.type() == QTransform::TxNone)
+ return;
+
+ if (invertible && delta.type() == QTransform::TxTranslate) {
+#ifdef QPAINTBUFFER_DEBUG_DRAW
+ qDebug() << "QPaintBufferEngine: transformChanged (translate only) " << state()->matrix;
+#endif
+ QPaintBufferCommand *cmd =
+ buffer->addCommand(QPaintBufferPrivate::Cmd_Translate);
+
+ qreal data[] = { delta.dx(), delta.dy() };
+ cmd->extra = buffer->addData((qreal *) data, 2);
+ return;
+ }
+
// ### accumulate, like in QBrush case...
if (!buffer->commands.isEmpty()
&& buffer->commands.last().id == QPaintBufferPrivate::Cmd_SetTransform) {
@@ -1013,6 +1041,7 @@ void QPaintBufferEngine::drawTextItem(const QPointF &pos, const QTextItem &ti)
void QPaintBufferEngine::setState(QPainterState *s)
{
+ Q_D(QPaintBufferEngine);
if (m_begin_detected) {
#ifdef QPAINTBUFFER_DEBUG_DRAW
qDebug() << "QPaintBufferEngine: setState: begin, ignoring.";
@@ -1031,6 +1060,8 @@ void QPaintBufferEngine::setState(QPainterState *s)
buffer->addCommand(QPaintBufferPrivate::Cmd_Restore);
}
+ d->last = s->matrix;
+
QPaintEngineEx::setState(s);
}
@@ -1152,6 +1183,15 @@ void QPainterReplayer::process(const QPaintBufferCommand &cmd)
painter->setTransform(xform * m_world_matrix);
break; }
+ case QPaintBufferPrivate::Cmd_Translate: {
+ QPointF delta(d->floats.at(cmd.extra), d->floats.at(cmd.extra+1));
+#ifdef QPAINTBUFFER_DEBUG_DRAW
+ qDebug() << " -> Cmd_Translate, offset: " << cmd.offset << delta;
+#endif
+ painter->translate(delta.x(), delta.y());
+ return;
+ }
+
case QPaintBufferPrivate::Cmd_SetCompositionMode: {
QPainter::CompositionMode mode = (QPainter::CompositionMode) cmd.extra;
#ifdef QPAINTBUFFER_DEBUG_DRAW
@@ -1797,8 +1837,28 @@ struct QPaintBufferCacheEntry
QVariant::Type type;
quint64 cacheKey;
};
+
+struct QPaintBufferCacheEntryV2
+{
+ enum Type {
+ ImageKey,
+ PixmapKey
+ };
+
+ struct Flags {
+ uint type : 8;
+ uint key : 24;
+ };
+
+ union {
+ Flags flags;
+ uint bits;
+ };
+};
+
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QPaintBufferCacheEntry)
+Q_DECLARE_METATYPE(QPaintBufferCacheEntryV2)
QT_BEGIN_NAMESPACE
QDataStream &operator<<(QDataStream &stream, const QPaintBufferCacheEntry &entry)
@@ -1811,10 +1871,22 @@ QDataStream &operator>>(QDataStream &stream, QPaintBufferCacheEntry &entry)
return stream >> entry.type >> entry.cacheKey;
}
+QDataStream &operator<<(QDataStream &stream, const QPaintBufferCacheEntryV2 &entry)
+{
+ return stream << entry.bits;
+}
+
+QDataStream &operator>>(QDataStream &stream, QPaintBufferCacheEntryV2 &entry)
+{
+ return stream >> entry.bits;
+}
+
static int qRegisterPaintBufferMetaTypes()
{
qRegisterMetaType<QPaintBufferCacheEntry>();
qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntry>("QPaintBufferCacheEntry");
+ qRegisterMetaType<QPaintBufferCacheEntryV2>();
+ qRegisterMetaTypeStreamOperators<QPaintBufferCacheEntryV2>("QPaintBufferCacheEntryV2");
return 0; // something
}
@@ -1823,6 +1895,9 @@ Q_CONSTRUCTOR_FUNCTION(qRegisterPaintBufferMetaTypes)
QDataStream &operator<<(QDataStream &stream, const QPaintBuffer &buffer)
{
+ QHash<qint64, uint> pixmapKeys;
+ QHash<qint64, uint> imageKeys;
+
QHash<qint64, QPixmap> pixmaps;
QHash<qint64, QImage> images;
@@ -1831,19 +1906,33 @@ QDataStream &operator<<(QDataStream &stream, const QPaintBuffer &buffer)
const QVariant &v = variants.at(i);
if (v.type() == QVariant::Image) {
const QImage image(v.value<QImage>());
- images[image.cacheKey()] = image;
- QPaintBufferCacheEntry entry;
- entry.type = QVariant::Image;
- entry.cacheKey = image.cacheKey();
+ QPaintBufferCacheEntryV2 entry;
+ entry.flags.type = QPaintBufferCacheEntryV2::ImageKey;
+
+ QHash<qint64, uint>::iterator it = imageKeys.find(image.cacheKey());
+ if (it != imageKeys.end()) {
+ entry.flags.key = *it;
+ } else {
+ imageKeys[image.cacheKey()] = entry.flags.key = images.size();
+ images[images.size()] = image;
+ }
+
variants[i] = QVariant::fromValue(entry);
} else if (v.type() == QVariant::Pixmap) {
const QPixmap pixmap(v.value<QPixmap>());
- pixmaps[pixmap.cacheKey()] = pixmap;
- QPaintBufferCacheEntry entry;
- entry.type = QVariant::Pixmap;
- entry.cacheKey = pixmap.cacheKey();
+ QPaintBufferCacheEntryV2 entry;
+ entry.flags.type = QPaintBufferCacheEntryV2::PixmapKey;
+
+ QHash<qint64, uint>::iterator it = pixmapKeys.find(pixmap.cacheKey());
+ if (it != pixmapKeys.end()) {
+ entry.flags.key = *it;
+ } else {
+ pixmapKeys[pixmap.cacheKey()] = entry.flags.key = pixmaps.size();
+ pixmaps[pixmaps.size()] = pixmap;
+ }
+
variants[i] = QVariant::fromValue(entry);
}
}
@@ -1885,6 +1974,15 @@ QDataStream &operator>>(QDataStream &stream, QPaintBuffer &buffer)
variants[i] = QVariant(images.value(entry.cacheKey));
else
variants[i] = QVariant(pixmaps.value(entry.cacheKey));
+ } else if (v.canConvert<QPaintBufferCacheEntryV2>()) {
+ QPaintBufferCacheEntryV2 entry = v.value<QPaintBufferCacheEntryV2>();
+
+ if (entry.flags.type == QPaintBufferCacheEntryV2::ImageKey)
+ variants[i] = QVariant(images.value(entry.flags.key));
+ else if (entry.flags.type == QPaintBufferCacheEntryV2::PixmapKey)
+ variants[i] = QVariant(pixmaps.value(entry.flags.key));
+ else
+ qWarning() << "operator<<(QDataStream &stream, QPaintBuffer &buffer): unrecognized cache entry type:" << entry.flags.type;
}
}
diff --git a/src/gui/painting/qpaintbuffer_p.h b/src/gui/painting/qpaintbuffer_p.h
index 41a26c5..0fde290 100644
--- a/src/gui/painting/qpaintbuffer_p.h
+++ b/src/gui/painting/qpaintbuffer_p.h
@@ -175,7 +175,6 @@ public:
Cmd_DrawText,
Cmd_DrawTextItem,
- Cmd_DrawStaticText,
Cmd_DrawImagePos,
Cmd_DrawImageRect,
@@ -184,6 +183,10 @@ public:
Cmd_DrawTiledPixmap,
Cmd_SystemStateChanged,
+ Cmd_Translate,
+ Cmd_DrawStaticText,
+
+ // new commands must be added above this line
Cmd_LastCommand
};
diff --git a/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp b/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp
index 13044f4..6bf9d6b 100644
--- a/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp
+++ b/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp
@@ -82,8 +82,13 @@ QTraceWindowSurface::~QTraceWindowSurface()
QFile outputFile(QString(QLatin1String("qtgraphics-%0.trace")).arg(winId));
if (outputFile.open(QIODevice::WriteOnly)) {
QDataStream out(&outputFile);
- out.writeBytes("qttrace", 7);
- out << *buffer << updates;
+ out.setFloatingPointPrecision(QDataStream::SinglePrecision);
+
+ out.writeBytes("qttraceV2", 9);
+
+ uint version = 1;
+
+ out << version << *buffer << updates;
}
delete buffer;
}
diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp
index 52b5287..23c5639 100644
--- a/src/testlib/qbenchmark.cpp
+++ b/src/testlib/qbenchmark.cpp
@@ -159,7 +159,7 @@ void QBenchmarkTestMethodData::setResult(
if (QBenchmarkGlobalData::current->iterationCount != -1)
accepted = true;
- if (QBenchmarkTestMethodData::current->runOnce) {
+ if (QBenchmarkTestMethodData::current->runOnce || !setByMacro) {
iterationCount = 1;
accepted = true;
}
diff --git a/tests/auto/qgl_threads/tst_openglthreading.cpp b/tests/auto/qgl_threads/tst_openglthreading.cpp
index f0c889c..6634869 100644
--- a/tests/auto/qgl_threads/tst_openglthreading.cpp
+++ b/tests/auto/qgl_threads/tst_openglthreading.cpp
@@ -45,6 +45,10 @@
#include <QtOpenGL/QtOpenGL>
#include "tst_openglthreading.h"
+#ifdef Q_WS_X11
+#include <private/qt_x11_p.h>
+#endif
+
#define RUNNING_TIME 5000
tst_OpenGLThreading::tst_OpenGLThreading(QObject *parent)
@@ -114,9 +118,9 @@ public:
{
setAutoBufferSwap(false);
}
-
+
void paintEvent(QPaintEvent *)
- {
+ {
m_thread->lock();
makeCurrent();
QPainter p(this);
@@ -273,22 +277,22 @@ void tst_OpenGLThreading::textureUploadInThread()
if that works, we're in good shape..
*/
-static inline float random() { return (rand() % 100) / 100.f; }
+static inline float qrandom() { return (rand() % 100) / 100.f; }
void renderAScene(int w, int h)
{
#ifdef QT_OPENGL_ES_2
QGLShaderProgram program;
- program.addShaderFromSourceCode(QGLShader::Vertex, "attribute highp vec2 pos; void main() { gl_Position = position; }");
+ program.addShaderFromSourceCode(QGLShader::Vertex, "attribute highp vec2 pos; void main() { gl_Position = vec4(pos.xy, 1.0, 1.0); }");
program.addShaderFromSourceCode(QGLShader::Fragment, "uniform lowp vec4 color; void main() { gl_FragColor = color; }");
+ program.bindAttributeLocation("pos", 0);
program.bind();
int colorId = program.uniformLocation("color");
- program.bindAttributeLocation("pos", 0);
- glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableVertexAttribArray(0);
for (int i=0; i<1000; ++i) {
- float pos[] = {
+ GLfloat pos[] = {
(rand() % 100) / 100.,
(rand() % 100) / 100.,
(rand() % 100) / 100.,
@@ -297,7 +301,7 @@ void renderAScene(int w, int h)
(rand() % 100) / 100.
};
- glVertexAttributePointer(0, 2, GL_FLOAT, false, 0, pos);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, pos);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
}
#else
@@ -313,12 +317,12 @@ void renderAScene(int w, int h)
for (int i=0;i<1000; ++i) {
glBegin(GL_TRIANGLES);
- glColor3f(random(), random(), random());
- glVertex2f(random() * w, random() * h);
- glColor3f(random(), random(), random());
- glVertex2f(random() * w, random() * h);
- glColor3f(random(), random(), random());
- glVertex2f(random() * w, random() * h);
+ glColor3f(qrandom(), qrandom(), qrandom());
+ glVertex2f(qrandom() * w, qrandom() * h);
+ glColor3f(qrandom(), qrandom(), qrandom());
+ glVertex2f(qrandom() * w, qrandom() * h);
+ glColor3f(qrandom(), qrandom(), qrandom());
+ glVertex2f(qrandom() * w, qrandom() * h);
glEnd();
}
#endif
@@ -339,10 +343,6 @@ public:
mutex.unlock();
};
- void sendResizeEvent(QResizeEvent *e) {
- QGLWidget::resizeEvent(e);
- }
-
QMutex mutex;
QSize newSize;
};
@@ -367,13 +367,13 @@ public:
while (time.elapsed() < RUNNING_TIME && !failure) {
+
m_widget->mutex.lock();
QSize s = m_widget->newSize;
m_widget->mutex.unlock();
+
if (s != m_size) {
- QResizeEvent e(s, m_size);
- m_widget->sendResizeEvent(&e);
- m_size = s;
+ glViewport(0, 0, s.width(), s.height());
}
if (QGLContext::currentContext() != m_widget->context()) {
@@ -392,9 +392,9 @@ public:
glReadPixels(w / 2, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color);
m_widget->swapBuffers();
-
-
}
+
+ m_widget->doneCurrent();
}
bool failure;
@@ -438,6 +438,12 @@ void tst_OpenGLThreading::renderInThread()
widget.update(100 + value, 100 + value, 20, 20);
qApp->processEvents();
value = -value;
+
+#ifdef Q_WS_WIN
+ Sleep(100);
+#else
+ usleep(100 * 1000);
+#endif
}
QVERIFY(!thread.failure);
@@ -446,7 +452,17 @@ void tst_OpenGLThreading::renderInThread()
+int main(int argc, char **argv)
+{
+#ifdef Q_WS_X11
+ XInitThreads();
+#endif
-QTEST_MAIN(tst_OpenGLThreading);
+ QApplication app(argc, argv);
+ QTEST_DISABLE_KEYPAD_NAVIGATION \
+
+ tst_OpenGLThreading tc;
+ return QTest::qExec(&tc, argc, argv);
+}
#include "tst_openglthreading.moc"
diff --git a/tests/auto/qgl_threads/tst_openglthreading.pro b/tests/auto/qgl_threads/tst_openglthreading.pro
index b60bc10..9312c05 100644
--- a/tests/auto/qgl_threads/tst_openglthreading.pro
+++ b/tests/auto/qgl_threads/tst_openglthreading.pro
@@ -1,4 +1,11 @@
+############################################################
+# Project file for autotest for file qgl.h
+############################################################
+
+load(qttest_p4)
+requires(contains(QT_CONFIG,opengl))
+QT += opengl
+
HEADERS += tst_openglthreading.h
SOURCES += tst_openglthreading.cpp
-QT += testlib opengl
diff --git a/tests/benchmarks/gui/painting/painting.pro b/tests/benchmarks/gui/painting/painting.pro
index 878567d..2c042b5 100644
--- a/tests/benchmarks/gui/painting/painting.pro
+++ b/tests/benchmarks/gui/painting/painting.pro
@@ -2,4 +2,5 @@ TEMPLATE = subdirs
SUBDIRS = \
qpainter \
qregion \
- qtransform
+ qtransform \
+ qtracebench
diff --git a/tests/benchmarks/gui/painting/qtracebench/qtracebench.pro b/tests/benchmarks/gui/painting/qtracebench/qtracebench.pro
new file mode 100644
index 0000000..56ec8bb
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/qtracebench.pro
@@ -0,0 +1,10 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qtracebench
+
+INCLUDEPATH += . $$QT_SOURCE_TREE/src/3rdparty/harfbuzz/src
+
+RESOURCES += qtracebench.qrc
+
+SOURCES += tst_qtracebench.cpp
+
diff --git a/tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc b/tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc
new file mode 100644
index 0000000..5569550
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc
@@ -0,0 +1,10 @@
+<RCC>
+ <qresource>
+ <file>traces/basicdrawing.trace</file>
+ <file>traces/webkit.trace</file>
+ <file>traces/textedit.trace</file>
+ <file>traces/creator.trace</file>
+ <file>traces/qmlphoneconcept.trace</file>
+ <file>traces/qmlsamegame.trace</file>
+ </qresource>
+</RCC>
diff --git a/tests/benchmarks/gui/painting/qtracebench/traces/basicdrawing.trace b/tests/benchmarks/gui/painting/qtracebench/traces/basicdrawing.trace
new file mode 100644
index 0000000..0241d08
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/traces/basicdrawing.trace
Binary files differ
diff --git a/tests/benchmarks/gui/painting/qtracebench/traces/creator.trace b/tests/benchmarks/gui/painting/qtracebench/traces/creator.trace
new file mode 100644
index 0000000..55ee9e1
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/traces/creator.trace
Binary files differ
diff --git a/tests/benchmarks/gui/painting/qtracebench/traces/qmlphoneconcept.trace b/tests/benchmarks/gui/painting/qtracebench/traces/qmlphoneconcept.trace
new file mode 100644
index 0000000..835ebfa
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/traces/qmlphoneconcept.trace
Binary files differ
diff --git a/tests/benchmarks/gui/painting/qtracebench/traces/qmlsamegame.trace b/tests/benchmarks/gui/painting/qtracebench/traces/qmlsamegame.trace
new file mode 100644
index 0000000..1d76195
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/traces/qmlsamegame.trace
Binary files differ
diff --git a/tests/benchmarks/gui/painting/qtracebench/traces/textedit.trace b/tests/benchmarks/gui/painting/qtracebench/traces/textedit.trace
new file mode 100644
index 0000000..998716d
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/traces/textedit.trace
Binary files differ
diff --git a/tests/benchmarks/gui/painting/qtracebench/traces/webkit.trace b/tests/benchmarks/gui/painting/qtracebench/traces/webkit.trace
new file mode 100644
index 0000000..43e752d
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/traces/webkit.trace
Binary files differ
diff --git a/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp
new file mode 100644
index 0000000..ff2633d
--- /dev/null
+++ b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp
@@ -0,0 +1,262 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 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 <qtest.h>
+
+#include <QtGui>
+
+#include <private/qpaintengineex_p.h>
+#include <private/qpaintbuffer_p.h>
+
+//TESTED_FILES=
+
+class ReplayWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ ReplayWidget(const QString &filename);
+
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+ bool done() const { return m_done; }
+ qreal result() const { return m_result; }
+
+public slots:
+ void updateRect();
+
+public:
+ QList<QRegion> updates;
+ QPaintBuffer buffer;
+
+ int currentFrame;
+ int currentIteration;
+ QTime timer;
+
+ QList<uint> visibleUpdates;
+ QList<uint> iterationTimes;
+ QString filename;
+
+ bool m_done;
+ qreal m_result;
+
+ uint m_total;
+};
+
+void ReplayWidget::updateRect()
+{
+ if (!visibleUpdates.isEmpty())
+ update(updates.at(visibleUpdates.at(currentFrame)));
+}
+
+void ReplayWidget::paintEvent(QPaintEvent *)
+{
+ if (m_done)
+ return;
+
+ QPainter p(this);
+
+ // if partial updates don't work
+ // p.setClipRegion(frames.at(currentFrame).updateRegion);
+
+ buffer.draw(&p, visibleUpdates.at(currentFrame));
+
+ ++currentFrame;
+ if (currentFrame >= visibleUpdates.size()) {
+ currentFrame = 0;
+ ++currentIteration;
+
+ uint currentElapsed = timer.isNull() ? 0 : timer.elapsed();
+ timer.restart();
+
+ m_total += currentElapsed;
+
+ // warm up for at most 5 iterations or half a second
+ if (currentIteration >= 5 || m_total >= 500) {
+ iterationTimes << currentElapsed;
+
+ if (iterationTimes.size() >= 5) {
+ qreal mean = 0;
+ qreal stddev = 0;
+ uint min = INT_MAX;
+
+ for (int i = 0; i < iterationTimes.size(); ++i) {
+ mean += iterationTimes.at(i);
+ min = qMin(min, iterationTimes.at(i));
+ }
+
+ mean /= qreal(iterationTimes.size());
+
+ for (int i = 0; i < iterationTimes.size(); ++i) {
+ qreal delta = iterationTimes.at(i) - mean;
+ stddev += delta * delta;
+ }
+
+ stddev = qSqrt(stddev / iterationTimes.size());
+
+ qSort(iterationTimes.begin(), iterationTimes.end());
+ uint median = iterationTimes.at(iterationTimes.size() / 2);
+
+ stddev = 100 * stddev / mean;
+ // do 100 iterations, break earlier if we spend more than 5 seconds or have a low std deviation after 2 seconds
+ if (iterationTimes.size() >= 100 || m_total >= 5000 || (m_total >= 2000 && stddev < 4)) {
+ printf("%s, iterations: %d, frames: %d, min(ms): %d, median(ms): %d, stddev: %f %%, max(fps): %f\n", qPrintable(filename),
+ iterationTimes.size(), visibleUpdates.size(), min, median, stddev, 1000. * visibleUpdates.size() / min);
+ m_result = min;
+ m_done = true;
+ return;
+ }
+ }
+ }
+ }
+}
+
+void ReplayWidget::resizeEvent(QResizeEvent *event)
+{
+ visibleUpdates.clear();
+
+ QRect bounds = rect();
+ for (int i = 0; i < updates.size(); ++i) {
+ if (updates.at(i).intersects(bounds))
+ visibleUpdates << i;
+ }
+
+ if (visibleUpdates.size() != updates.size())
+ printf("Warning: skipped %d frames due to limited resolution\n", updates.size() - visibleUpdates.size());
+
+}
+
+ReplayWidget::ReplayWidget(const QString &filename_)
+ : currentFrame(0)
+ , currentIteration(0)
+ , filename(filename_)
+ , m_done(false)
+ , m_result(0)
+ , m_total(0)
+{
+ setWindowTitle(filename);
+ QFile file(filename);
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ printf("Failed to load input file '%s'\n", qPrintable(filename_));
+ return;
+ }
+
+ QDataStream in(&file);
+
+ char *data;
+ uint size;
+ in.readBytes(data, size);
+ bool isTraceFile = size >= 7 && qstrncmp(data, "qttrace", 7) == 0;
+ uint version = 0;
+ if (size == 9 && qstrncmp(data, "qttraceV2", 9) == 0) {
+ in.setFloatingPointPrecision(QDataStream::SinglePrecision);
+ in >> version;
+ }
+
+ delete [] data;
+ if (!isTraceFile) {
+ printf("File '%s' is not a trace file\n", qPrintable(filename_));
+ return;
+ }
+
+ in >> buffer >> updates;
+
+ resize(buffer.boundingRect().size().toSize());
+
+ setAutoFillBackground(false);
+ setAttribute(Qt::WA_NoSystemBackground);
+}
+
+
+class tst_QTraceBench : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void trace();
+ void trace_data();
+};
+
+static const QLatin1String prefix(":/traces/");
+
+void tst_QTraceBench::trace_data()
+{
+ QTest::addColumn<QString>("filename");
+
+ QTest::newRow("basicdrawing") << (prefix + "basicdrawing.trace");
+ QTest::newRow("webkit") << (prefix + "webkit.trace");
+ QTest::newRow("creator") << (prefix + "creator.trace");
+ QTest::newRow("textedit") << (prefix + "textedit.trace");
+ QTest::newRow("qmlphoneconcept") << (prefix + "qmlphoneconcept.trace");
+ QTest::newRow("qmlsamegame") << (prefix + "qmlsamegame.trace");
+}
+
+void tst_QTraceBench::trace()
+{
+ QFETCH(QString, filename);
+
+ QFile file(filename);
+ if (!file.exists()) {
+ qWarning() << "Missing file" << filename;
+ return;
+ }
+
+ ReplayWidget widget(filename);
+
+ if (widget.updates.isEmpty()) {
+ qWarning() << "No trace updates" << filename;
+ return;
+ }
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ while (!widget.done()) {
+ widget.updateRect();
+ QApplication::processEvents();
+ }
+
+ QTest::setBenchmarkResult(widget.result(), QTest::WalltimeMilliseconds);
+}
+
+QTEST_MAIN(tst_QTraceBench)
+#include "tst_qtracebench.moc"
diff --git a/tools/qttracereplay/main.cpp b/tools/qttracereplay/main.cpp
index a932d72..be7906b 100644
--- a/tools/qttracereplay/main.cpp
+++ b/tools/qttracereplay/main.cpp
@@ -49,7 +49,7 @@ class ReplayWidget : public QWidget
{
Q_OBJECT
public:
- ReplayWidget(const QString &filename);
+ ReplayWidget(const QString &filename, int from, int to, bool single);
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
@@ -68,6 +68,11 @@ public:
QList<uint> visibleUpdates;
QList<uint> iterationTimes;
QString filename;
+
+ int from;
+ int to;
+
+ bool single;
};
void ReplayWidget::updateRect()
@@ -89,6 +94,11 @@ void ReplayWidget::paintEvent(QPaintEvent *)
currentFrame = 0;
++currentIteration;
+ if (single) {
+ deleteLater();
+ return;
+ }
+
if (currentIteration == 3)
timer.start();
else if (currentIteration > 3) {
@@ -137,20 +147,28 @@ void ReplayWidget::resizeEvent(QResizeEvent *event)
visibleUpdates.clear();
QRect bounds = rect();
- for (int i = 0; i < updates.size(); ++i) {
+
+ int first = qMax(0, from);
+ int last = qMin(unsigned(to), unsigned(updates.size()));
+ for (int i = first; i < last; ++i) {
if (updates.at(i).intersects(bounds))
visibleUpdates << i;
}
- if (visibleUpdates.size() != updates.size())
- printf("Warning: skipped %d frames due to limited resolution\n", updates.size() - visibleUpdates.size());
+ int range = last - first;
+
+ if (visibleUpdates.size() != range)
+ printf("Warning: skipped %d frames due to limited resolution\n", range - visibleUpdates.size());
}
-ReplayWidget::ReplayWidget(const QString &filename_)
+ReplayWidget::ReplayWidget(const QString &filename_, int from_, int to_, bool single_)
: currentFrame(0)
, currentIteration(0)
, filename(filename_)
+ , from(from_)
+ , to(to_)
+ , single(single_)
{
setWindowTitle(filename);
QFile file(filename);
@@ -165,15 +183,21 @@ ReplayWidget::ReplayWidget(const QString &filename_)
char *data;
uint size;
in.readBytes(data, size);
- bool isTraceFile = size == 7 && qstrncmp(data, "qttrace", 7) == 0;
- delete [] data;
+ bool isTraceFile = size >= 7 && qstrncmp(data, "qttrace", 7) == 0;
+
+ uint version = 0;
+ if (size == 9 && qstrncmp(data, "qttraceV2", 9) == 0) {
+ in.setFloatingPointPrecision(QDataStream::SinglePrecision);
+ in >> version;
+ }
+
if (!isTraceFile) {
printf("File '%s' is not a trace file\n", qPrintable(filename_));
return;
}
in >> buffer >> updates;
- printf("Read paint buffer with %d frames\n", buffer.numFrames());
+ printf("Read paint buffer version %d with %d frames\n", version, buffer.numFrames());
resize(buffer.boundingRect().size().toSize());
@@ -189,17 +213,53 @@ int main(int argc, char **argv)
if (argc <= 1 || qstrcmp(argv[1], "-h") == 0 || qstrcmp(argv[1], "--help") == 0) {
printf("Replays a tracefile generated with '-graphicssystem trace'\n");
- printf("Usage:\n > %s [traceFile]\n", argv[0]);
+ printf("Usage:\n > %s [OPTIONS] [traceFile]\n", argv[0]);
+ printf("OPTIONS\n"
+ " --range=from-to to specify a frame range.\n"
+ " --singlerun to do only one run (without statistics)\n");
return 1;
}
- QFile file(argv[1]);
+ QFile file(app.arguments().last());
if (!file.exists()) {
- printf("%s does not exist\n", argv[1]);
+ printf("%s does not exist\n", qPrintable(app.arguments().last()));
return 1;
}
- ReplayWidget *widget = new ReplayWidget(argv[1]);
+ bool single = false;
+
+ int from = 0;
+ int to = -1;
+ for (int i = 1; i < app.arguments().size() - 1; ++i) {
+ QString arg = app.arguments().at(i);
+ if (arg.startsWith(QLatin1String("--range="))) {
+ QString rest = arg.mid(8);
+ QStringList components = rest.split(QLatin1Char('-'));
+
+ bool ok1 = false;
+ bool ok2 = false;
+ int fromCandidate = 0;
+ int toCandidate = 0;
+ if (components.size() == 2) {
+ fromCandidate = components.first().toInt(&ok1);
+ toCandidate = components.last().toInt(&ok2);
+ }
+
+ if (ok1 && ok2) {
+ from = fromCandidate;
+ to = toCandidate;
+ } else {
+ printf("ERROR: malformed syntax in argument %s\n", qPrintable(arg));
+ }
+ } else if (arg == QLatin1String("--singlerun")) {
+ single = true;
+ } else {
+ printf("Unrecognized argument: %s\n", qPrintable(arg));
+ return 1;
+ }
+ }
+
+ ReplayWidget *widget = new ReplayWidget(app.arguments().last(), from, to, single);
if (!widget->updates.isEmpty()) {
widget->show();