From 2ec9f20ad7204ad1121a49d862d625821323f7b4 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Tue, 16 Feb 2010 15:50:15 +0100 Subject: Make threading use-cases work for X11 --- tests/auto/qgl_threads/tst_openglthreading.cpp | 40 ++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/tests/auto/qgl_threads/tst_openglthreading.cpp b/tests/auto/qgl_threads/tst_openglthreading.cpp index f0c889c..408bfc8 100644 --- a/tests/auto/qgl_threads/tst_openglthreading.cpp +++ b/tests/auto/qgl_threads/tst_openglthreading.cpp @@ -45,6 +45,10 @@ #include #include "tst_openglthreading.h" +#ifdef Q_WS_X11 +#include +#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); @@ -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" -- cgit v0.12 From f07d97150549f6817c351643e1c8b0ff163803ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 17 Feb 2010 12:47:08 +0100 Subject: Always accept values reported directly using QTest::setBenchmarkResult. Reviewed-by: jasplin --- src/testlib/qbenchmark.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } -- cgit v0.12 From 204df42586c1b0fef24d1a72f51302ad4f719e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 25 Jan 2010 14:14:52 +0100 Subject: Added --range and --single arguments to qttracereplay. Makes it easy to split a large trace into several sub-traces by running the qttracereplay with -graphicssystem trace. Reviewed-by: Gunnar Sletta --- tools/qttracereplay/main.cpp | 72 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/tools/qttracereplay/main.cpp b/tools/qttracereplay/main.cpp index a932d72..82373f7 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 visibleUpdates; QList 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); @@ -189,17 +207,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(); -- cgit v0.12 From 5cd93666050076053d547d1b3ba4041b8fae58ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 18 Feb 2010 12:46:27 +0100 Subject: Added trace replayer benchmark. Now we can easily add trace files generated with -graphicssystem trace for benchmarking on all relevant platforms. Reviewed-by: Gunnar Sletta --- tests/benchmarks/gui/painting/painting.pro | 3 +- .../gui/painting/qtracebench/qtracebench.pro | 10 + .../gui/painting/qtracebench/qtracebench.qrc | 8 + .../painting/qtracebench/traces/basicdrawing.trace | Bin 0 -> 366739 bytes .../gui/painting/qtracebench/traces/creator.trace | Bin 0 -> 541031 bytes .../gui/painting/qtracebench/traces/textedit.trace | Bin 0 -> 60042 bytes .../gui/painting/qtracebench/traces/webkit.trace | Bin 0 -> 451391 bytes .../gui/painting/qtracebench/tst_qtracebench.cpp | 255 +++++++++++++++++++++ 8 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 tests/benchmarks/gui/painting/qtracebench/qtracebench.pro create mode 100644 tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc create mode 100644 tests/benchmarks/gui/painting/qtracebench/traces/basicdrawing.trace create mode 100644 tests/benchmarks/gui/painting/qtracebench/traces/creator.trace create mode 100644 tests/benchmarks/gui/painting/qtracebench/traces/textedit.trace create mode 100644 tests/benchmarks/gui/painting/qtracebench/traces/webkit.trace create mode 100644 tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp 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..cea0e2f --- /dev/null +++ b/tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc @@ -0,0 +1,8 @@ + + + traces/basicdrawing.trace + traces/webkit.trace + traces/textedit.trace + traces/creator.trace + + 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 Binary files /dev/null and b/tests/benchmarks/gui/painting/qtracebench/traces/basicdrawing.trace 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 Binary files /dev/null and b/tests/benchmarks/gui/painting/qtracebench/traces/creator.trace 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 Binary files /dev/null and b/tests/benchmarks/gui/painting/qtracebench/traces/textedit.trace 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 Binary files /dev/null and b/tests/benchmarks/gui/painting/qtracebench/traces/webkit.trace 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..c3afffa --- /dev/null +++ b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp @@ -0,0 +1,255 @@ +/**************************************************************************** +** +** 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 + +#include + +#include +#include + +//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 updates; + QPaintBuffer buffer; + + int currentFrame; + int currentIteration; + QTime timer; + + QList visibleUpdates; + QList 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; + delete [] data; + 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()); + + 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("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"); +} + +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" -- cgit v0.12 From 37d4bde65a28a10efdd9c09b88007acd7339629a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 18 Feb 2010 11:58:03 +0100 Subject: Reduced the memory footprint of qttrace files. A couple of improvements have been made: * Use single precision floats for the traces. * Reduce the number of variant wrapped transforms by introducing a new translate command. * Reduce the number of bytes streamed per image / pixmap draw command. * Add versioning info to qttrace files to be more future proof. Reviewed-by: Gunnar Sletta --- src/gui/painting/qpaintbuffer.cpp | 114 +++++++++++++++++++-- src/gui/painting/qpaintbuffer_p.h | 1 + .../trace/qgraphicssystem_trace.cpp | 9 +- .../gui/painting/qtracebench/tst_qtracebench.cpp | 10 +- tools/qttracereplay/main.cpp | 12 ++- 5 files changed, 131 insertions(+), 15 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(); qRegisterMetaTypeStreamOperators("QPaintBufferCacheEntry"); + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators("QPaintBufferCacheEntryV2"); return 0; // something } @@ -1823,6 +1895,9 @@ Q_CONSTRUCTOR_FUNCTION(qRegisterPaintBufferMetaTypes) QDataStream &operator<<(QDataStream &stream, const QPaintBuffer &buffer) { + QHash pixmapKeys; + QHash imageKeys; + QHash pixmaps; QHash 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()); - images[image.cacheKey()] = image; - QPaintBufferCacheEntry entry; - entry.type = QVariant::Image; - entry.cacheKey = image.cacheKey(); + QPaintBufferCacheEntryV2 entry; + entry.flags.type = QPaintBufferCacheEntryV2::ImageKey; + + QHash::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()); - pixmaps[pixmap.cacheKey()] = pixmap; - QPaintBufferCacheEntry entry; - entry.type = QVariant::Pixmap; - entry.cacheKey = pixmap.cacheKey(); + QPaintBufferCacheEntryV2 entry; + entry.flags.type = QPaintBufferCacheEntryV2::PixmapKey; + + QHash::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 entry = v.value(); + + 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..8c2bb6b 100644 --- a/src/gui/painting/qpaintbuffer_p.h +++ b/src/gui/painting/qpaintbuffer_p.h @@ -184,6 +184,7 @@ public: Cmd_DrawTiledPixmap, Cmd_SystemStateChanged, + Cmd_Translate, 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/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp index c3afffa..86daca0 100644 --- a/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp +++ b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp @@ -185,7 +185,13 @@ ReplayWidget::ReplayWidget(const QString &filename_) char *data; uint size; in.readBytes(data, size); - bool isTraceFile = size == 7 && qstrncmp(data, "qttrace", 7) == 0; + 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_)); @@ -193,7 +199,7 @@ ReplayWidget::ReplayWidget(const QString &filename_) } 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()); diff --git a/tools/qttracereplay/main.cpp b/tools/qttracereplay/main.cpp index 82373f7..be7906b 100644 --- a/tools/qttracereplay/main.cpp +++ b/tools/qttracereplay/main.cpp @@ -183,15 +183,21 @@ ReplayWidget::ReplayWidget(const QString &filename_, int from_, int to_, bool si 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()); -- cgit v0.12 From 0eb8492cd2eed1bf18ae183603d8975ab780bda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 18 Feb 2010 13:42:10 +0100 Subject: Fixed old trace files no longer working. Move new static text draw command to the end to avoid invalidating existing traces. Reviewed-by: Eskil --- src/gui/painting/qpaintbuffer_p.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qpaintbuffer_p.h b/src/gui/painting/qpaintbuffer_p.h index 8c2bb6b..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, @@ -185,6 +184,9 @@ public: Cmd_SystemStateChanged, Cmd_Translate, + Cmd_DrawStaticText, + + // new commands must be added above this line Cmd_LastCommand }; -- cgit v0.12 From b4f812dfbed935c1b1770e4bea253e76e5c4684b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 18 Feb 2010 12:27:05 +0100 Subject: Added two QML based traces to trace benchmark. --- .../gui/painting/qtracebench/qtracebench.qrc | 2 ++ .../painting/qtracebench/traces/qmlphoneconcept.trace | Bin 0 -> 337439 bytes .../gui/painting/qtracebench/traces/qmlsamegame.trace | Bin 0 -> 246423 bytes .../gui/painting/qtracebench/tst_qtracebench.cpp | 2 ++ 4 files changed, 4 insertions(+) create mode 100644 tests/benchmarks/gui/painting/qtracebench/traces/qmlphoneconcept.trace create mode 100644 tests/benchmarks/gui/painting/qtracebench/traces/qmlsamegame.trace diff --git a/tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc b/tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc index cea0e2f..5569550 100644 --- a/tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc +++ b/tests/benchmarks/gui/painting/qtracebench/qtracebench.qrc @@ -4,5 +4,7 @@ traces/webkit.trace traces/textedit.trace traces/creator.trace + traces/qmlphoneconcept.trace + traces/qmlsamegame.trace 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 Binary files /dev/null and b/tests/benchmarks/gui/painting/qtracebench/traces/qmlphoneconcept.trace 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 Binary files /dev/null and b/tests/benchmarks/gui/painting/qtracebench/traces/qmlsamegame.trace differ diff --git a/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp index 86daca0..0931f96 100644 --- a/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp +++ b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp @@ -227,6 +227,8 @@ void tst_QTraceBench::trace_data() 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() -- cgit v0.12 From 16f1fd886147fd12b471d8746bb85029da2be8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 18 Feb 2010 14:37:47 +0100 Subject: Removed redundant debug output from trace benchmark. --- tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp index 0931f96..ff2633d 100644 --- a/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp +++ b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp @@ -199,7 +199,6 @@ ReplayWidget::ReplayWidget(const QString &filename_) } in >> buffer >> updates; - printf("Read paint buffer version %d with %d frames\n", version, buffer.numFrames()); resize(buffer.boundingRect().size().toSize()); -- cgit v0.12 From e7945c14cbfe3cae93ff92509a7eac7dfd786abe Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Thu, 18 Feb 2010 14:38:50 +0100 Subject: Fix threaded gl autotest build failure on GLES2 Reviewed-By: Gunnar --- tests/auto/qgl_threads/tst_openglthreading.cpp | 24 ++++++++++++------------ tests/auto/qgl_threads/tst_openglthreading.pro | 9 ++++++++- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/auto/qgl_threads/tst_openglthreading.cpp b/tests/auto/qgl_threads/tst_openglthreading.cpp index 408bfc8..6634869 100644 --- a/tests/auto/qgl_threads/tst_openglthreading.cpp +++ b/tests/auto/qgl_threads/tst_openglthreading.cpp @@ -277,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., @@ -301,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 @@ -317,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 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 -- cgit v0.12