From 7f43bd48595025961989fcd51bee0271a275b475 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 25 May 2009 17:31:42 +1000 Subject: Add basic client/server debugging support The canvas framerate monitor now uses this support. --- src/declarative/canvas/canvas.pri | 4 +- src/declarative/canvas/monitor/main.cpp | 287 ------------- src/declarative/canvas/monitor/monitor.pro | 8 - src/declarative/canvas/qsimplecanvas.cpp | 18 +- src/declarative/canvas/qsimplecanvas_p.h | 6 +- .../canvas/qsimplecanvasdebugplugin.cpp | 93 +++++ .../canvas/qsimplecanvasdebugplugin_p.h | 68 +++ src/declarative/canvas/qsimplecanvasserver.cpp | 134 ------ src/declarative/canvas/qsimplecanvasserver_p.h | 75 ---- src/declarative/debugger/debugger.pri | 10 +- src/declarative/debugger/qmldebugclient.cpp | 190 +++++++++ src/declarative/debugger/qmldebugclient.h | 97 +++++ src/declarative/debugger/qmldebugserver.cpp | 283 +++++++++++++ src/declarative/debugger/qmldebugserver.h | 81 ++++ src/declarative/debugger/qpacketprotocol.cpp | 462 +++++++++++++++++++++ src/declarative/debugger/qpacketprotocol.h | 81 ++++ tools/qmldebugger/canvasframerate.cpp | 305 ++++++++++++++ tools/qmldebugger/canvasframerate.h | 23 + tools/qmldebugger/main.cpp | 103 +++++ tools/qmldebugger/qmldebugger.pro | 10 + 20 files changed, 1816 insertions(+), 522 deletions(-) delete mode 100644 src/declarative/canvas/monitor/main.cpp delete mode 100644 src/declarative/canvas/monitor/monitor.pro create mode 100644 src/declarative/canvas/qsimplecanvasdebugplugin.cpp create mode 100644 src/declarative/canvas/qsimplecanvasdebugplugin_p.h delete mode 100644 src/declarative/canvas/qsimplecanvasserver.cpp delete mode 100644 src/declarative/canvas/qsimplecanvasserver_p.h create mode 100644 src/declarative/debugger/qmldebugclient.cpp create mode 100644 src/declarative/debugger/qmldebugclient.h create mode 100644 src/declarative/debugger/qmldebugserver.cpp create mode 100644 src/declarative/debugger/qmldebugserver.h create mode 100644 src/declarative/debugger/qpacketprotocol.cpp create mode 100644 src/declarative/debugger/qpacketprotocol.h create mode 100644 tools/qmldebugger/canvasframerate.cpp create mode 100644 tools/qmldebugger/canvasframerate.h create mode 100644 tools/qmldebugger/main.cpp create mode 100644 tools/qmldebugger/qmldebugger.pro diff --git a/src/declarative/canvas/canvas.pri b/src/declarative/canvas/canvas.pri index 8abfd99..9bdd3fa 100644 --- a/src/declarative/canvas/canvas.pri +++ b/src/declarative/canvas/canvas.pri @@ -2,7 +2,7 @@ SOURCES += \ canvas/qsimplecanvas.cpp \ canvas/qsimplecanvasitem.cpp \ canvas/qsimplecanvasfilter.cpp \ - canvas/qsimplecanvasserver.cpp + canvas/qsimplecanvasdebugplugin.cpp HEADERS += \ canvas/qsimplecanvas.h \ @@ -11,7 +11,7 @@ HEADERS += \ canvas/qsimplecanvas_p.h \ canvas/qsimplecanvasitem_p.h \ canvas/qsimplecanvasfilter_p.h \ - canvas/qsimplecanvasserver_p.h + canvas/qsimplecanvasdebugplugin_p.h contains(QT_CONFIG, opengles2): SOURCES += canvas/qsimplecanvas_opengl.cpp else:contains(QT_CONFIG, opengles1): SOURCES += canvas/qsimplecanvas_opengl1.cpp diff --git a/src/declarative/canvas/monitor/main.cpp b/src/declarative/canvas/monitor/main.cpp deleted file mode 100644 index f5f40bd..0000000 --- a/src/declarative/canvas/monitor/main.cpp +++ /dev/null @@ -1,287 +0,0 @@ -#include -#include -#include -#include -#include - -class QLineGraph : public QWidget -{ -Q_OBJECT -public: - QLineGraph(QWidget * = 0); - - void setPosition(int); - -public slots: - void addSample(int, int, int, int, bool); - -protected: - virtual void paintEvent(QPaintEvent *); - virtual void mousePressEvent(QMouseEvent *); - virtual void resizeEvent(QResizeEvent *); - virtual void showEvent(QShowEvent *); - -private slots: - void scrollbarChanged(int); - -private: - void positionScrollbar(); - void updateScrollbar(); - void drawSample(QPainter *, int, const QRect &); - void drawTime(QPainter *, const QRect &); - struct Sample { - int sample[4]; - bool isBreak; - }; - QList _samples; - - QScrollBar sb; - int position; - int samplesPerWidth; - int resolutionForHeight; - bool ignoreScroll; -}; - -QLineGraph::QLineGraph(QWidget *parent) -: QWidget(parent), sb(Qt::Horizontal, this), position(-1), samplesPerWidth(99), resolutionForHeight(50), ignoreScroll(false) -{ - sb.setMaximum(0); - sb.setMinimum(0); - sb.setSingleStep(1); - - QObject::connect(&sb, SIGNAL(valueChanged(int)), this, SLOT(scrollbarChanged(int))); -} - -void QLineGraph::scrollbarChanged(int v) -{ - if(ignoreScroll) - return; - - position = v; - update(); -} - -void QLineGraph::positionScrollbar() -{ - sb.setFixedWidth(width()); - sb.move(0, height() - sb.height()); -} - -void QLineGraph::resizeEvent(QResizeEvent *e) -{ - QWidget::resizeEvent(e); - positionScrollbar(); -} - -void QLineGraph::showEvent(QShowEvent *e) -{ - QWidget::showEvent(e); - positionScrollbar(); -} - -void QLineGraph::mousePressEvent(QMouseEvent *) -{ - if(position == -1) { - position = qMax(0, _samples.count() - samplesPerWidth - 1); - } else { - position = -1; - } - update(); -} - -void QLineGraph::updateScrollbar() -{ - ignoreScroll = true; - sb.setMaximum(qMax(0, _samples.count() - samplesPerWidth - 1)); - - if(position == -1) { - sb.setValue(sb.maximum()); - } else { - sb.setValue(position); - } - ignoreScroll = false; -} - -void QLineGraph::addSample(int a, int b, int c, int d, bool isBreak) -{ - Sample s; - s.isBreak = isBreak; - s.sample[0] = a; - s.sample[1] = b; - s.sample[2] = c; - s.sample[3] = d; - _samples << s; - updateScrollbar(); - update(); -} - -void QLineGraph::drawTime(QPainter *p, const QRect &rect) -{ - if(_samples.isEmpty()) - return; - - int first = position; - if(first == -1) - first = qMax(0, _samples.count() - samplesPerWidth - 1); - int last = qMin(_samples.count() - 1, first + samplesPerWidth); - - qreal scaleX = qreal(rect.width()) / qreal(samplesPerWidth); - - int t = 0; - - for(int ii = first; ii <= last; ++ii) { - int sampleTime = _samples.at(ii).sample[3] / 1000; - if(sampleTime != t) { - - int xEnd = rect.left() + scaleX * (ii - first); - p->drawLine(xEnd, rect.bottom(), xEnd, rect.bottom() + 7); - - QRect text(xEnd - 30, rect.bottom() + 10, 60, 30); - - p->drawText(text, Qt::AlignHCenter | Qt::AlignTop, QString::number(_samples.at(ii).sample[3])); - - t = sampleTime; - } - } - -} - -void QLineGraph::drawSample(QPainter *p, int s, const QRect &rect) -{ - if(_samples.isEmpty()) - return; - - int first = position; - if(first == -1) - first = qMax(0, _samples.count() - samplesPerWidth - 1); - int last = qMin(_samples.count() - 1, first + samplesPerWidth); - - qreal scaleY = rect.height() / resolutionForHeight; - qreal scaleX = qreal(rect.width()) / qreal(samplesPerWidth); - - int xEnd; - int lastXEnd = rect.left(); - - p->save(); - p->setPen(Qt::NoPen); - for(int ii = first + 1; ii <= last; ++ii) { - - xEnd = rect.left() + scaleX * (ii - first); - int yEnd = rect.bottom() - _samples.at(ii).sample[s] * scaleY; - - if (!(s == 0 && _samples.at(ii).isBreak)) - p->drawRect(QRect(lastXEnd, yEnd, scaleX, _samples.at(ii).sample[s] * scaleY)); - - lastXEnd = xEnd; - } - p->restore(); -} - -void QLineGraph::paintEvent(QPaintEvent *) -{ - QPainter p(this); - p.setRenderHint(QPainter::Antialiasing); - - - QRect r(50, 10, width() - 60, height() - 60); - p.setBrush(QColor("lightsteelblue")); - drawSample(&p, 0, r); - - p.setBrush(QColor("pink")); - drawSample(&p, 1, r); - - p.setBrush(QColor("green")); - drawSample(&p, 2, r); - - p.setBrush(Qt::NoBrush); - p.drawRect(r); - - for(int ii = 0; ii <= resolutionForHeight; ++ii) { - int y = 1 + r.bottom() - ii * r.height() / resolutionForHeight; - - if((ii % 10) == 0) { - p.drawLine(r.left() - 20, y, r.left(), y); - QRect text(r.left() - 20 - 53, y - 10, 50, 20); - p.drawText(text, Qt::AlignRight | Qt::AlignVCenter, QString::number(ii)); - } else { - p.drawLine(r.left() - 7, y, r.left(), y); - } - } - - drawTime(&p, r); -} - -class MyReader : public QObject -{ -Q_OBJECT -public: - MyReader(const QString &host, int port); - -signals: - void sample(int, int, int, int, bool); - -private slots: - void readyRead(); - -private: - QTcpSocket *socket; - - int la; - int lb; - int ld; -}; - -MyReader::MyReader(const QString &host, int port) -: socket(0), la(-1) -{ - socket = new QTcpSocket(this); - QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); - socket->connectToHost(host, port); - socket->waitForConnected(); -} - -void MyReader::readyRead() -{ - static int la = -1; - static int lb; - static int ld; - - if(socket->canReadLine()) { - QString line = socket->readLine(); - - int a; - int b; - int c; - int d; - int isBreak; - sscanf(line.toLatin1().constData(), "%d %d %d %d %d", &a, &b, &c, &d, &isBreak); - - if (la != -1) - emit sample(c, lb, la, ld, isBreak); - - la = a; - lb = b; - ld = d; - } -} - -int main(int argc, char ** argv) -{ - if(argc != 3) { - qWarning() << "Usage:" << argv[0] << "host port"; - return -1; - } - - QApplication app(argc, argv); - - MyReader reader(argv[1], atoi(argv[2])); - - QLineGraph graph; - QObject::connect(&reader, SIGNAL(sample(int,int,int,int,bool)), &graph, SLOT(addSample(int,int,int,int,bool))); - graph.setFixedSize(800, 600); - graph.show(); - - return app.exec(); -} - -#include "main.moc" diff --git a/src/declarative/canvas/monitor/monitor.pro b/src/declarative/canvas/monitor/monitor.pro deleted file mode 100644 index e3b0a29..0000000 --- a/src/declarative/canvas/monitor/monitor.pro +++ /dev/null @@ -1,8 +0,0 @@ -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . -QT += network - -# Input -SOURCES += main.cpp diff --git a/src/declarative/canvas/qsimplecanvas.cpp b/src/declarative/canvas/qsimplecanvas.cpp index fbd5014..7d2c9c5 100644 --- a/src/declarative/canvas/qsimplecanvas.cpp +++ b/src/declarative/canvas/qsimplecanvas.cpp @@ -53,7 +53,7 @@ #include #endif #include "qboxlayout.h" -#include "qsimplecanvasserver_p.h" +#include "qsimplecanvasdebugplugin_p.h" #include "qsimplecanvas.h" @@ -533,8 +533,8 @@ void QSimpleCanvasGraphicsView::paintEvent(QPaintEvent *pe) int frametimer = canvas->frameTimer.elapsed(); gfxCanvasTiming.append(QSimpleCanvasTiming(r, frametimer, canvas->lrpTime, tbf)); canvas->lrpTime = 0; - if (canvas->canvasServer) - canvas->canvasServer->addTiming(canvas->lrpTime, frametimer, tbf); + if (canvas->debugPlugin) + canvas->debugPlugin->addTiming(canvas->lrpTime, frametimer, tbf); } void QSimpleCanvasGraphicsView::focusInEvent(QFocusEvent *) @@ -573,12 +573,8 @@ void QSimpleCanvasPrivate::init(QSimpleCanvas::CanvasMode mode) if (continuousUpdate()) qWarning("QSimpleCanvas: Continuous update enabled"); - QByteArray env = qgetenv("GFX_CANVAS_SERVER_PORT"); - if (!env.isEmpty()){ - int port = env.toInt(); - if (port >= 1024) - canvasServer = new QSimpleCanvasServer(port, q); - } + if (QmlDebugServerPlugin::isDebuggingEnabled()) + debugPlugin = new QSimpleCanvasDebugPlugin(q); root = new QSimpleCanvasRootLayer(q); root->setActiveFocusPanel(true); @@ -950,8 +946,8 @@ bool QSimpleCanvas::event(QEvent *e) int frametimer = d->frameTimer.elapsed(); gfxCanvasTiming.append(QSimpleCanvasTiming(r, frametimer, d->lrpTime, tbf)); - if (d->canvasServer) - d->canvasServer->addTiming(d->lrpTime, frametimer, tbf); + if (d->debugPlugin) + d->debugPlugin->addTiming(d->lrpTime, frametimer, tbf); d->lrpTime = 0; if (continuousUpdate()) queueUpdate(); diff --git a/src/declarative/canvas/qsimplecanvas_p.h b/src/declarative/canvas/qsimplecanvas_p.h index 9c3408e..d9ed4ac 100644 --- a/src/declarative/canvas/qsimplecanvas_p.h +++ b/src/declarative/canvas/qsimplecanvas_p.h @@ -101,12 +101,12 @@ private: }; class QGLFramebufferObject; -class QSimpleCanvasServer; +class QSimpleCanvasDebugPlugin; class QSimpleCanvasPrivate { public: QSimpleCanvasPrivate(QSimpleCanvas *canvas) - : q(canvas), timer(0), root(0), lrpTime(0), canvasServer(0), focusItem(0), + : q(canvas), timer(0), root(0), lrpTime(0), debugPlugin(0), focusItem(0), lastFocusItem(0), lastMouseItem(0), isSetup(false), view(0) #if defined(QFX_RENDER_OPENGL) @@ -139,7 +139,7 @@ public: QTime frameTimer; QTime lrpTimer; - QSimpleCanvasServer *canvasServer; + QSimpleCanvasDebugPlugin *debugPlugin; QStack focusPanels; QHash focusPanelData; diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp new file mode 100644 index 0000000..0ce5378 --- /dev/null +++ b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsimplecanvasdebugplugin_p.h" +#include "qdebug.h" +#include + +QT_BEGIN_NAMESPACE + +class FrameBreakAnimation : public QAbstractAnimation +{ +public: + FrameBreakAnimation(QSimpleCanvasDebugPlugin *s) + : QAbstractAnimation(s), server(s) + { + start(); + } + + virtual int duration() const { return -1; } + virtual void updateCurrentTime(int msecs) { + server->frameBreak(); + } + +private: + QSimpleCanvasDebugPlugin *server; +}; + +QSimpleCanvasDebugPlugin::QSimpleCanvasDebugPlugin(QObject *parent) +: QmlDebugServerPlugin("CanvasFrameRate", parent), _breaks(0) +{ + _time.start(); + new FrameBreakAnimation(this); +} + +void QSimpleCanvasDebugPlugin::addTiming(quint32 paint, + quint32 repaint, + quint32 timeBetweenFrames) +{ + bool isFrameBreak = _breaks > 1; + _breaks = 0; + int e = _time.elapsed(); + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << (int)paint << (int)repaint << (int)timeBetweenFrames << (int)e + << (bool)isFrameBreak; + sendMessage(data); +} + +void QSimpleCanvasDebugPlugin::frameBreak() +{ + _breaks++; +} + +QT_END_NAMESPACE + diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin_p.h b/src/declarative/canvas/qsimplecanvasdebugplugin_p.h new file mode 100644 index 0000000..0c76f38 --- /dev/null +++ b/src/declarative/canvas/qsimplecanvasdebugplugin_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSIMPLECANVASDEBUGPLUGIN_P_H +#define QSIMPLECANVASDEBUGPLUGIN_P_H + +#include "qobject.h" +#include "qtcpserver.h" +#include "qtcpsocket.h" +#include "qdatetime.h" +#include + +QT_BEGIN_NAMESPACE +class QSimpleCanvasDebugPlugin : public QmlDebugServerPlugin +{ +public: + QSimpleCanvasDebugPlugin(QObject *parent = 0); + + void addTiming(quint32, quint32, quint32); + +private: + friend class FrameBreakAnimation; + void frameBreak(); + int _breaks; + QTime _time; +}; +QT_END_NAMESPACE + +#endif // QSIMPLECANVASDEBUGPLUGIN_P_H + diff --git a/src/declarative/canvas/qsimplecanvasserver.cpp b/src/declarative/canvas/qsimplecanvasserver.cpp deleted file mode 100644 index ed781b8..0000000 --- a/src/declarative/canvas/qsimplecanvasserver.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimplecanvasserver_p.h" -#include "qdebug.h" -#ifndef Q_OS_WIN32 -#include -#endif -#include - -QT_BEGIN_NAMESPACE - -class FrameBreakAnimation : public QAbstractAnimation -{ -public: - FrameBreakAnimation(QSimpleCanvasServer *s) - : QAbstractAnimation(s), server(s) - { - start(); - } - - virtual int duration() const { return -1; } - virtual void updateCurrentTime(int msecs) { - server->frameBreak(); - } - -private: - QSimpleCanvasServer *server; -}; - -QSimpleCanvasServer::QSimpleCanvasServer(int port, QObject *parent) -: QObject(parent), _breaks(0), _tcpServer(new QTcpServer(this)) -{ - QObject::connect(_tcpServer, SIGNAL(newConnection()), - this, SLOT(newConnection())); - - _time.start(); - - new FrameBreakAnimation(this); - if (!_tcpServer->listen(QHostAddress::Any, port)) { - qWarning() << "QSimpleCanvasServer: Cannot listen on port" << port; - return; - } -} - -void QSimpleCanvasServer::newConnection() -{ - QTcpSocket *socket = _tcpServer->nextPendingConnection(); - QObject::connect(socket, SIGNAL(disconnected()), - this, SLOT(disconnected())); - _tcpClients << socket; -} - -void QSimpleCanvasServer::addTiming(quint32 paint, - quint32 repaint, - quint32 timeBetweenFrames) -{ - /* - quint32 data[3]; - data[0] = ::htonl(paint); - data[1] = ::htonl(repaint); - data[2] = ::htonl(timeBetweenFrames); - */ - - bool isFrameBreak = _breaks > 1; - _breaks = 0; - int e = _time.elapsed(); - QString d = QString::number(paint) + QLatin1String(" ") + QString::number(repaint) + QLatin1String(" ") + QString::number(timeBetweenFrames) + QLatin1String(" ") + QString::number(e) + QLatin1String(" ") + QString::number(isFrameBreak) + QLatin1String("\n"); - QByteArray ba = d.toLatin1(); - - // XXX - for (int ii = 0; ii < _tcpClients.count(); ++ii) -// _tcpClients.at(ii)->write((const char *)data, 12); - _tcpClients.at(ii)->write(ba.constData(), ba.length()); -} - -void QSimpleCanvasServer::frameBreak() -{ - _breaks++; -} - -void QSimpleCanvasServer::disconnected() -{ - QTcpSocket *socket = static_cast(sender()); - - for (int ii = 0; ii < _tcpClients.count(); ++ii) { - if (_tcpClients.at(ii) == socket) { - socket->disconnect(); - socket->deleteLater(); - _tcpClients.removeAt(ii); - return; - } - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasserver_p.h b/src/declarative/canvas/qsimplecanvasserver_p.h deleted file mode 100644 index ce04e8d..0000000 --- a/src/declarative/canvas/qsimplecanvasserver_p.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMPLECANVASSERVER_P_H -#define QSIMPLECANVASSERVER_P_H - -#include "qobject.h" -#include "qtcpserver.h" -#include "qtcpsocket.h" -#include "qdatetime.h" - - -QT_BEGIN_NAMESPACE -class QSimpleCanvasServer : public QObject -{ -Q_OBJECT -public: - QSimpleCanvasServer(int port, QObject *parent); - - void addTiming(quint32, quint32, quint32); - -private Q_SLOTS: - void newConnection(); - void disconnected(); - -private: - friend class FrameBreakAnimation; - void frameBreak(); - int _breaks; - - QTcpServer *_tcpServer; - QList _tcpClients; - QTime _time; -}; - -QT_END_NAMESPACE -#endif // GFXCANVASSERVER_P_H diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index c386d74..121cb98 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -3,11 +3,17 @@ SOURCES += debugger/qmldebugger.cpp \ debugger/qmlpropertyview.cpp \ debugger/qmlwatches.cpp \ debugger/qmlobjecttree.cpp \ - debugger/qmlcanvasdebugger.cpp + debugger/qmlcanvasdebugger.cpp \ + debugger/qpacketprotocol.cpp \ + debugger/qmldebugserver.cpp \ + debugger/qmldebugclient.cpp HEADERS += debugger/qmldebugger.h \ debugger/qmldebuggerstatus.h \ debugger/qmlpropertyview_p.h \ debugger/qmlwatches_p.h \ debugger/qmlobjecttree_p.h \ - debugger/qmlcanvasdebugger_p.h + debugger/qmlcanvasdebugger_p.h \ + debugger/qpacketprotocol.h \ + debugger/qmldebugserver.h \ + debugger/qmldebugclient.h diff --git a/src/declarative/debugger/qmldebugclient.cpp b/src/declarative/debugger/qmldebugclient.cpp new file mode 100644 index 0000000..7a304ef --- /dev/null +++ b/src/declarative/debugger/qmldebugclient.cpp @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmldebugclient.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlDebugClientPrivate : public QObject +{ + Q_OBJECT +public: + QmlDebugClientPrivate(QmlDebugClient *c); + QmlDebugClient *q; + QPacketProtocol *protocol; + + QStringList enabled; + QHash plugins; +public slots: + void connected(); + void readyRead(); +}; + +QmlDebugClientPrivate::QmlDebugClientPrivate(QmlDebugClient *c) +: QObject(c), q(c), protocol(0) +{ + protocol = new QPacketProtocol(q, this); + QObject::connect(c, SIGNAL(connected()), this, SLOT(connected())); + QObject::connect(protocol, SIGNAL(readyRead()), this, SLOT(readyRead())); +} + +void QmlDebugClientPrivate::connected() +{ + QPacket pack; + pack << QString(QLatin1String("QmlDebugServer")) << QStringList(); + protocol->send(pack); +} + +void QmlDebugClientPrivate::readyRead() +{ + QPacket pack = protocol->read(); + QString name; QByteArray message; + pack >> name >> message; + + QHash::Iterator iter = + plugins.find(name); + if (iter == plugins.end()) { + qWarning() << "QmlDebugClient: Message received for missing plugin" << name; + } else { + (*iter)->messageReceived(message); + } +} + +QmlDebugClient::QmlDebugClient(QObject *parent) +: QTcpSocket(parent), d(new QmlDebugClientPrivate(this)) +{ +} + +class QmlDebugClientPluginPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlDebugClientPlugin); +public: + QmlDebugClientPluginPrivate(); + + QString name; + QmlDebugClient *client; + bool enabled; +}; + +QmlDebugClientPluginPrivate::QmlDebugClientPluginPrivate() +: client(0), enabled(false) +{ +} + +QmlDebugClientPlugin::QmlDebugClientPlugin(const QString &name, + QmlDebugClient *parent) +: QObject(*(new QmlDebugClientPluginPrivate), parent) +{ + Q_D(QmlDebugClientPlugin); + d->name = name; + d->client = parent; + + if (!d->client) + return; + + if (d->client->d->plugins.contains(name)) { + qWarning() << "QmlDebugClientPlugin: Conflicting plugin name" << name; + d->client = 0; + } else { + d->client->d->plugins.insert(name, this); + } +} + +QString QmlDebugClientPlugin::name() const +{ + Q_D(const QmlDebugClientPlugin); + return d->name; +} + +bool QmlDebugClientPlugin::isEnabled() const +{ + Q_D(const QmlDebugClientPlugin); + return d->enabled; +} + +void QmlDebugClientPlugin::setEnabled(bool e) +{ + Q_D(QmlDebugClientPlugin); + if (e == d->enabled) + return; + + d->enabled = e; + + if (d->client) { + if (e) + d->client->d->enabled.append(d->name); + else + d->client->d->enabled.removeAll(d->name); + + if (d->client->state() == QTcpSocket::ConnectedState) { + QPacket pack; + pack << QString(QLatin1String("QmlDebugServer")); + if (e) pack << (int)1; + else pack << (int)2; + pack << d->name; + d->client->d->protocol->send(pack); + } + } +} + +void QmlDebugClientPlugin::sendMessage(const QByteArray &message) +{ + Q_D(QmlDebugClientPlugin); + + if (!d->client || d->client->state() != QTcpSocket::ConnectedState) + return; + + QPacket pack; + pack << d->name << message; + d->client->d_func()->protocol->send(pack); +} + +void QmlDebugClientPlugin::messageReceived(const QByteArray &) +{ +} + +#include "qmldebugclient.moc" + +QT_END_NAMESPACE diff --git a/src/declarative/debugger/qmldebugclient.h b/src/declarative/debugger/qmldebugclient.h new file mode 100644 index 0000000..d765822 --- /dev/null +++ b/src/declarative/debugger/qmldebugclient.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLDEBUGCLIENT_H +#define QMLDEBUGCLIENT_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QmlDebugClientPrivate; +class Q_DECLARATIVE_EXPORT QmlDebugClient : public QTcpSocket +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlDebugClient) + Q_DISABLE_COPY(QmlDebugClient) +public: + QmlDebugClient(QObject * = 0); + +private: + QmlDebugClientPrivate *d; + friend class QmlDebugClientPlugin; + friend class QmlDebugClientPluginPrivate; +}; + +class QmlDebugClientPluginPrivate; +class Q_DECLARATIVE_EXPORT QmlDebugClientPlugin : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlDebugClientPlugin) + Q_DISABLE_COPY(QmlDebugClientPlugin) + +public: + QmlDebugClientPlugin(const QString &, QmlDebugClient *parent); + + QString name() const; + + bool isEnabled() const; + void setEnabled(bool); + + void sendMessage(const QByteArray &); + +protected: + virtual void messageReceived(const QByteArray &); + +private: + friend class QmlDebugClient; + friend class QmlDebugClientPrivate; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLDEBUGCLIENT_H diff --git a/src/declarative/debugger/qmldebugserver.cpp b/src/declarative/debugger/qmldebugserver.cpp new file mode 100644 index 0000000..bce7e6d --- /dev/null +++ b/src/declarative/debugger/qmldebugserver.cpp @@ -0,0 +1,283 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmldebugserver.h" +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlDebugServerPrivate; +class QmlDebugServer : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlDebugServer) + Q_DISABLE_COPY(QmlDebugServer) +public: + static QmlDebugServer *instance(); + +private slots: + void readyRead(); + +private: + friend class QmlDebugServerPlugin; + friend class QmlDebugServerPluginPrivate; + QmlDebugServer(int); +}; + +class QmlDebugServerPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlDebugServer); +public: + QmlDebugServerPrivate(); + void init(int port); + + QTcpSocket *connection; + QPacketProtocol *protocol; + QHash plugins; + QStringList enabledPlugins; +}; + +class QmlDebugServerPluginPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlDebugServerPlugin); +public: + QmlDebugServerPluginPrivate(); + + QString name; + QmlDebugServer *server; +}; + +QmlDebugServerPrivate::QmlDebugServerPrivate() +: connection(0), protocol(0) +{ +} + +void QmlDebugServerPrivate::init(int port) +{ + Q_Q(QmlDebugServer); + QTcpServer server; + + if (!server.listen(QHostAddress::Any, port)) { + qWarning("QmlDebugServer: Unable to listen on port %d", port); + return; + } + + qWarning("QmlDebugServer: Waiting for connection on port %d...", port); + + if (!server.waitForNewConnection(-1)) { + qWarning("QmlDebugServer: Connection error"); + return; + } + + connection = server.nextPendingConnection(); + connection->setParent(q); + protocol = new QPacketProtocol(connection, q); + + // ### Wait for hello + while (!protocol->packetsAvailable()) { + connection->waitForReadyRead(); + } + QPacket hello = protocol->read(); + QString name; + hello >> name >> enabledPlugins; + if (name != QLatin1String("QmlDebugServer")) { + qWarning("QmlDebugServer: Invalid hello message"); + delete protocol; delete connection; connection = 0; protocol = 0; + return; + } + + QObject::connect(protocol, SIGNAL(readyRead()), q, SLOT(readyRead())); + q->readyRead(); + + qWarning("QmlDebugServer: Connection established"); +} + +QmlDebugServer *QmlDebugServer::instance() +{ + static bool envTested = false; + static QmlDebugServer *server = 0; + + if (!envTested) { + envTested = true; + QByteArray env = qgetenv("QML_DEBUG_SERVER_PORT"); + + bool ok = false; + int port = env.toInt(&ok); + + if (ok && port > 1024) + server = new QmlDebugServer(port); + } + + if (server && server->d_func()->connection) + return server; + else + return 0; +} + +QmlDebugServer::QmlDebugServer(int port) +: QObject(*(new QmlDebugServerPrivate)) +{ + Q_D(QmlDebugServer); + d->init(port); +} + +void QmlDebugServer::readyRead() +{ + Q_D(QmlDebugServer); + + QString debugServer(QLatin1String("QmlDebugServer")); + + while (d->protocol->packetsAvailable()) { + QPacket pack = d->protocol->read(); + + QString name; + pack >> name; + + if (name == debugServer) { + int op = -1; QString plugin; + pack >> op >> plugin; + + if (op == 1) { + // Enable + if (!d->enabledPlugins.contains(plugin)) { + d->enabledPlugins.append(plugin); + QHash::Iterator iter = + d->plugins.find(plugin); + if (iter != d->plugins.end()) + (*iter)->enabledChanged(true); + } + + } else if (op == 2) { + // Disable + if (d->enabledPlugins.contains(plugin)) { + d->enabledPlugins.removeAll(plugin); + QHash::Iterator iter = + d->plugins.find(plugin); + if (iter != d->plugins.end()) + (*iter)->enabledChanged(false); + } + } else { + qWarning("QmlDebugServer: Invalid control message %d", op); + } + + } else { + QByteArray message; + pack >> message; + + QHash::Iterator iter = + d->plugins.find(name); + if (iter == d->plugins.end()) { + qWarning() << "QmlDebugServer: Message received for missing plugin" << name; + } else { + (*iter)->messageReceived(message); + } + } + } +} + +QmlDebugServerPluginPrivate::QmlDebugServerPluginPrivate() +: server(0) +{ +} + +QmlDebugServerPlugin::QmlDebugServerPlugin(const QString &name, QObject *parent) +: QObject(*(new QmlDebugServerPluginPrivate), parent) +{ + Q_D(QmlDebugServerPlugin); + d->name = name; + d->server = QmlDebugServer::instance(); + + if (!d->server) + return; + + if (d->server->d_func()->plugins.contains(name)) { + qWarning() << "QmlDebugServerPlugin: Conflicting plugin name" << name; + d->server = 0; + } else { + d->server->d_func()->plugins.insert(name, this); + } +} + +QString QmlDebugServerPlugin::name() const +{ + Q_D(const QmlDebugServerPlugin); + return d->name; +} + +bool QmlDebugServerPlugin::isEnabled() const +{ + Q_D(const QmlDebugServerPlugin); + return (d->server && d->server->d_func()->enabledPlugins.contains(d->name)); +} + +bool QmlDebugServerPlugin::isDebuggingEnabled() +{ + return QmlDebugServer::instance() != 0; +} + +void QmlDebugServerPlugin::sendMessage(const QByteArray &message) +{ + Q_D(QmlDebugServerPlugin); + + if (!d->server || !d->server->d_func()->connection) + return; + + QPacket pack; + pack << d->name << message; + d->server->d_func()->protocol->send(pack); +} + +void QmlDebugServerPlugin::enabledChanged(bool) +{ +} + +void QmlDebugServerPlugin::messageReceived(const QByteArray &) +{ +} + +#include "qmldebugserver.moc" + +QT_END_NAMESPACE diff --git a/src/declarative/debugger/qmldebugserver.h b/src/declarative/debugger/qmldebugserver.h new file mode 100644 index 0000000..8ee2cfb --- /dev/null +++ b/src/declarative/debugger/qmldebugserver.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLDEBUGSERVER_H +#define QMLDEBUGSERVER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QmlDebugServerPluginPrivate; +class QmlDebugServerPlugin : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlDebugServerPlugin) + Q_DISABLE_COPY(QmlDebugServerPlugin) +public: + QmlDebugServerPlugin(const QString &, QObject *parent = 0); + + QString name() const; + + bool isEnabled() const; + + void sendMessage(const QByteArray &); + + static bool isDebuggingEnabled(); + +protected: + virtual void enabledChanged(bool); + virtual void messageReceived(const QByteArray &); + +private: + friend class QmlDebugServer; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLDEBUGSERVER_H + diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp new file mode 100644 index 0000000..6911b89 --- /dev/null +++ b/src/declarative/debugger/qpacketprotocol.cpp @@ -0,0 +1,462 @@ +/**************************************************************************** +** +** This file is part of the $PACKAGE_NAME$. +** +** Copyright (C) $THISYEAR$ $COMPANY_NAME$. +** +** $QT_EXTENDED_DUAL_LICENSE$ +** +****************************************************************************/ + +#include "qpacketprotocol.h" +#include + +#define MAX_PACKET_SIZE 0x7FFFFFFF + +/*! + \class QPacketProtocol + + \brief The QPacketProtocol class encapsulates communicating discrete packets + across fragmented IO channels, such as TCP sockets. + + QPacketProtocol makes it simple to send arbitrary sized data "packets" across + fragmented transports such as TCP and UDP. + + As transmission boundaries are not respected, sending packets over protocols + like TCP frequently involves "stitching" them back together at the receiver. + QPacketProtocol makes this easier by performing this task for you. Packet + data sent using QPacketProtocol is prepended with a 4-byte size header + allowing the receiving QPacketProtocol to buffer the packet internally until + it has all been received. QPacketProtocol does not perform any sanity + checking on the size or on the data, so this class should only be used in + prototyping or trusted situations where DOS attacks are unlikely. + + QPacketProtocol does not perform any communications itself. Instead it can + operate on any QIODevice that supports the QIODevice::readyRead() signal. A + logical "packet" is encapsulated by the companion QPacket class. The + following example shows two ways to send data using QPacketProtocol. The + transmitted data is equivalent in both. + + \code + QTcpSocket socket; + // ... connect socket ... + + QPacketProtocol protocol(&socket); + + // Send packet the quick way + protocol.send() << "Hello world" << 123; + + // Send packet the longer way + QPacket packet; + packet << "Hello world" << 123; + protocol.send(packet); + \endcode + + Likewise, the following shows how to read data from QPacketProtocol, assuming + that the QPacketProtocol::readyRead() signal has been emitted. + + \code + // ... QPacketProtocol::readyRead() is emitted ... + + int a; + QByteArray b; + + // Receive packet the quick way + protocol.read() >> a >> b; + + // Receive packet the longer way + QPacket packet = protocol.read(); + p >> a >> b; + \endcode + + \ingroup io + \sa QPacket +*/ + +class QPacketProtocolPrivate : public QObject +{ +Q_OBJECT +public: + QPacketProtocolPrivate(QPacketProtocol * parent, QIODevice * _dev) + : QObject(parent), inProgressSize(-1), maxPacketSize(MAX_PACKET_SIZE), + dev(_dev) + { + Q_ASSERT(4 == sizeof(qint32)); + + QObject::connect(this, SIGNAL(readyRead()), + parent, SIGNAL(readyRead())); + QObject::connect(this, SIGNAL(packetWritten()), + parent, SIGNAL(packetWritten())); + QObject::connect(this, SIGNAL(invalidPacket()), + parent, SIGNAL(invalidPacket())); + QObject::connect(dev, SIGNAL(readyRead()), + this, SLOT(readyToRead())); + QObject::connect(dev, SIGNAL(aboutToClose()), + this, SLOT(aboutToClose())); + QObject::connect(dev, SIGNAL(bytesWritten(qint64)), + this, SLOT(bytesWritten(qint64))); + } + +signals: + void readyRead(); + void packetWritten(); + void invalidPacket(); + +public slots: + void aboutToClose() + { + inProgress.clear(); + sendingPackets.clear(); + inProgressSize = -1; + } + + void bytesWritten(qint64 bytes) + { + Q_ASSERT(!sendingPackets.isEmpty()); + + while(bytes) { + if(sendingPackets.at(0) > bytes) { + sendingPackets[0] -= bytes; + bytes = 0; + } else { + bytes -= sendingPackets.at(0); + sendingPackets.removeFirst(); + emit packetWritten(); + } + } + } + + void readyToRead() + { + if(-1 == inProgressSize) { + // We need a size header of sizeof(qint32) + if(sizeof(qint32) > dev->bytesAvailable()) + return; + + // Read size header + int read = dev->read((char *)&inProgressSize, sizeof(qint32)); + Q_ASSERT(read == sizeof(qint32)); + Q_UNUSED(read); + + // Check sizing constraints + if(inProgressSize > maxPacketSize) { + QObject::disconnect(dev, SIGNAL(readyRead()), + this, SLOT(readyToRead())); + QObject::disconnect(dev, SIGNAL(aboutToClose()), + this, SLOT(aboutToClose())); + QObject::disconnect(dev, SIGNAL(bytesWritten(qint64)), + this, SLOT(bytesWritten(qint64))); + dev = 0; + emit invalidPacket(); + return; + } + + inProgressSize -= sizeof(qint32); + + // Need to get trailing data + readyToRead(); + } else { + inProgress.append(dev->read(inProgressSize - inProgress.size())); + + if(inProgressSize == inProgress.size()) { + // Packet has arrived! + packets.append(inProgress); + inProgressSize = -1; + inProgress.clear(); + + emit readyRead(); + + // Need to get trailing data + readyToRead(); + } + } + } + +public: + QList sendingPackets; + QList packets; + QByteArray inProgress; + qint32 inProgressSize; + qint32 maxPacketSize; + QIODevice * dev; +}; + +/*! + Construct a QPacketProtocol instance that works on \a dev with the + specified \a parent. + */ +QPacketProtocol::QPacketProtocol(QIODevice * dev, QObject * parent) +: QObject(parent), d(new QPacketProtocolPrivate(this, dev)) +{ + Q_ASSERT(dev); +} + +/*! + Destroys the QPacketProtocol instance. + */ +QPacketProtocol::~QPacketProtocol() +{ +} + +/*! + Returns the maximum packet size allowed. By default this is + 2,147,483,647 bytes. + + If a packet claiming to be larger than the maximum packet size is received, + the QPacketProtocol::invalidPacket() signal is emitted. + + \sa QPacketProtocol::setMaximumPacketSize() + */ +qint32 QPacketProtocol::maximumPacketSize() const +{ + return d->maxPacketSize; +} + +/*! + Sets the maximum allowable packet size to \a max. + + \sa QPacketProtocol::maximumPacketSize() + */ +qint32 QPacketProtocol::setMaximumPacketSize(qint32 max) +{ + if(max > (signed)sizeof(qint32)) + d->maxPacketSize = max; + return d->maxPacketSize; +} + +/*! + Returns a streamable object that is transmitted on destruction. For example + + \code + protocol.send() << "Hello world" << 123; + \endcode + + will send a packet containing "Hello world" and 123. To construct more + complex packets, explicitly construct a QPacket instance. + */ +QPacketAutoSend QPacketProtocol::send() +{ + return QPacketAutoSend(this); +} + +/*! + \fn void QPacketProtocol::send(const QPacket & packet) + + Transmit the \a packet. + */ +void QPacketProtocol::send(const QPacket & p) +{ + if(p.b.isEmpty()) + return; // We don't send empty packets + + qint64 sendSize = p.b.size() + sizeof(qint32); + + d->sendingPackets.append(sendSize); + qint32 sendSize32 = sendSize; + qint64 writeBytes = d->dev->write((char *)&sendSize32, sizeof(qint32)); + Q_ASSERT(writeBytes == sizeof(qint32)); + writeBytes = d->dev->write(p.b); + Q_ASSERT(writeBytes == p.b.size()); +} + +/*! + Returns the number of received packets yet to be read. + */ +qint64 QPacketProtocol::packetsAvailable() const +{ + return d->packets.count(); +} + +/*! + Discard any unread packets. + */ +void QPacketProtocol::clear() +{ + d->packets.clear(); +} + +/*! + Return the next unread packet, or an invalid QPacket instance if no packets + are available. This method does NOT block. + */ +QPacket QPacketProtocol::read() +{ + if(0 == d->packets.count()) + return QPacket(); + + QPacket rv(d->packets.at(0)); + d->packets.removeFirst(); + return rv; +} + +/*! + Return the QIODevice passed to the QPacketProtocol constructor. +*/ +QIODevice * QPacketProtocol::device() +{ + return d->dev; +} + +/*! + \fn void QPacketProtocol::readyRead() + + Emitted whenever a new packet is received. Applications may use + QPacketProtocol::read() to retrieve this packet. + */ + +/*! + \fn void QPacketProtocol::invalidPacket() + + A packet larger than the maximum allowable packet size was received. The + packet will be discarded and, as it indicates corruption in the protocol, no + further packets will be received. + */ + +/*! + \fn void QPacketProtocol::packetWritten() + + Emitted each time a packet is completing written to the device. This signal + may be used for communications flow control. + */ + +/*! + \class QPacket + \inpublicgroup QtBaseModule + + \brief The QPacket class encapsulates an unfragmentable packet of data to be + transmitted by QPacketProtocol. + + The QPacket class works together with QPacketProtocol to make it simple to + send arbitrary sized data "packets" across fragmented transports such as TCP + and UDP. + + QPacket provides a QDataStream interface to an unfragmentable packet. + Applications should construct a QPacket, propagate it with data and then + transmit it over a QPacketProtocol instance. For example: + \code + QPacketProtocol protocol(...); + + QPacket myPacket; + myPacket << "Hello world!" << 123; + protocol.send(myPacket); + \endcode + + As long as both ends of the connection are using the QPacketProtocol class, + the data within this packet will be delivered unfragmented at the other end, + ready for extraction. + + \code + QByteArray greeting; + int count; + + QPacket myPacket = protocol.read(); + + myPacket >> greeting >> count; + \endcode + + Only packets returned from QPacketProtocol::read() may be read from. QPacket + instances constructed by directly by applications are for transmission only + and are considered "write only". Attempting to read data from them will + result in undefined behaviour. + + \ingroup io + \sa QPacketProtocol + */ + +/*! + Constructs an empty write-only packet. + */ +QPacket::QPacket() +: QDataStream(), buf(0) +{ + buf = new QBuffer(&b); + buf->open(QIODevice::WriteOnly); + setDevice(buf); +} + +/*! + Destroys the QPacket instance. + */ +QPacket::~QPacket() +{ + if(buf) { + delete buf; + buf = 0; + } +} + +/*! + Creates a copy of \a other. The initial stream positions are shared, but the + two packets are otherwise independant. + */ +QPacket::QPacket(const QPacket & other) +: QDataStream(), b(other.b), buf(0) +{ + buf = new QBuffer(&b); + buf->open(other.buf->openMode()); + setDevice(buf); +} + +/*! + \internal + */ +QPacket::QPacket(const QByteArray & ba) +: QDataStream(), b(ba), buf(0) +{ + buf = new QBuffer(&b); + buf->open(QIODevice::ReadOnly); + setDevice(buf); +} + +/*! + Returns true if this packet is empty - that is, contains no data. + */ +bool QPacket::isEmpty() const +{ + return b.isEmpty(); +} + +/*! + Clears data in the packet. This is useful for reusing one writable packet. + For example + \code + QPacketProtocol protocol(...); + + QPacket packet; + + packet << "Hello world!" << 123; + protocol.send(packet); + + packet.clear(); + packet << "Goodbyte world!" << 789; + protocol.send(packet); + \endcode + */ +void QPacket::clear() +{ + QBuffer::OpenMode oldMode = buf->openMode(); + buf->close(); + b.clear(); + buf->setBuffer(&b); // reset QBuffer internals with new size of b. + buf->open(oldMode); +} + +/*! + \class QPacketAutoSend + \inpublicgroup QtBaseModule + + \internal + */ +QPacketAutoSend::QPacketAutoSend(QPacketProtocol * _p) +: QPacket(), p(_p) +{ +} + +QPacketAutoSend::~QPacketAutoSend() +{ + if(!b.isEmpty()) + p->send(*this); +} + +#include "qpacketprotocol.moc" + diff --git a/src/declarative/debugger/qpacketprotocol.h b/src/declarative/debugger/qpacketprotocol.h new file mode 100644 index 0000000..6dd8bda --- /dev/null +++ b/src/declarative/debugger/qpacketprotocol.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** This file is part of the $PACKAGE_NAME$. +** +** Copyright (C) $THISYEAR$ $COMPANY_NAME$. +** +** $QT_EXTENDED_DUAL_LICENSE$ +** +****************************************************************************/ + +#ifndef QPACKETPROTOCOL_H +#define QPACKETPROTOCOL_H + +#include +#include + +class QIODevice; +class QBuffer; +class QPacket; +class QPacketAutoSend; +class QPacketProtocolPrivate; + +class Q_DECLARATIVE_EXPORT QPacketProtocol : public QObject +{ +Q_OBJECT +public: + explicit QPacketProtocol(QIODevice * dev, QObject * parent = 0); + virtual ~QPacketProtocol(); + + qint32 maximumPacketSize() const; + qint32 setMaximumPacketSize(qint32); + + QPacketAutoSend send(); + void send(const QPacket &); + + qint64 packetsAvailable() const; + QPacket read(); + + void clear(); + + QIODevice * device(); + +signals: + void readyRead(); + void invalidPacket(); + void packetWritten(); + +private: + QPacketProtocolPrivate * d; +}; + + +class Q_DECLARATIVE_EXPORT QPacket : public QDataStream +{ +public: + QPacket(); + QPacket(const QPacket &); + virtual ~QPacket(); + + void clear(); + bool isEmpty() const; + +protected: + friend class QPacketProtocol; + QPacket(const QByteArray & ba); + QByteArray b; + QBuffer * buf; +}; + +class Q_DECLARATIVE_EXPORT QPacketAutoSend : public QPacket +{ +public: + virtual ~QPacketAutoSend(); + +private: + friend class QPacketProtocol; + QPacketAutoSend(QPacketProtocol *); + QPacketProtocol * p; +}; + +#endif diff --git a/tools/qmldebugger/canvasframerate.cpp b/tools/qmldebugger/canvasframerate.cpp new file mode 100644 index 0000000..b1f412e --- /dev/null +++ b/tools/qmldebugger/canvasframerate.cpp @@ -0,0 +1,305 @@ +#include "canvasframerate.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class QLineGraph : public QWidget +{ +Q_OBJECT +public: + QLineGraph(QWidget * = 0); + + void setPosition(int); + +public slots: + void addSample(int, int, int, int, bool); + +protected: + virtual void paintEvent(QPaintEvent *); + virtual void mousePressEvent(QMouseEvent *); + virtual void resizeEvent(QResizeEvent *); + virtual void showEvent(QShowEvent *); + +private slots: + void scrollbarChanged(int); + +private: + void updateScrollbar(); + void drawSample(QPainter *, int, const QRect &); + void drawTime(QPainter *, const QRect &); + struct Sample { + int sample[4]; + bool isBreak; + }; + QList _samples; + + QScrollBar sb; + int position; + int samplesPerWidth; + int resolutionForHeight; + bool ignoreScroll; +}; + +QLineGraph::QLineGraph(QWidget *parent) +: QWidget(parent), sb(Qt::Horizontal, this), position(-1), samplesPerWidth(99), resolutionForHeight(50), ignoreScroll(false) +{ + sb.setMaximum(0); + sb.setMinimum(0); + sb.setSingleStep(1); + + QVBoxLayout *layout = new QVBoxLayout; + setLayout(layout); + layout->addStretch(2); + layout->addWidget(&sb); + QObject::connect(&sb, SIGNAL(valueChanged(int)), this, SLOT(scrollbarChanged(int))); +} + +void QLineGraph::scrollbarChanged(int v) +{ + if(ignoreScroll) + return; + + position = v; + update(); +} + +void QLineGraph::resizeEvent(QResizeEvent *e) +{ + QWidget::resizeEvent(e); +} + +void QLineGraph::showEvent(QShowEvent *e) +{ + QWidget::showEvent(e); +} + +void QLineGraph::mousePressEvent(QMouseEvent *) +{ + if(position == -1) { + position = qMax(0, _samples.count() - samplesPerWidth - 1); + } else { + position = -1; + } + update(); +} + +void QLineGraph::updateScrollbar() +{ + ignoreScroll = true; + sb.setMaximum(qMax(0, _samples.count() - samplesPerWidth - 1)); + + if(position == -1) { + sb.setValue(sb.maximum()); + } else { + sb.setValue(position); + } + ignoreScroll = false; +} + +void QLineGraph::addSample(int a, int b, int c, int d, bool isBreak) +{ + Sample s; + s.isBreak = isBreak; + s.sample[0] = a; + s.sample[1] = b; + s.sample[2] = c; + s.sample[3] = d; + _samples << s; + updateScrollbar(); + update(); +} + +void QLineGraph::setPosition(int p) +{ + scrollbarChanged(p); +} + +void QLineGraph::drawTime(QPainter *p, const QRect &rect) +{ + if(_samples.isEmpty()) + return; + + int first = position; + if(first == -1) + first = qMax(0, _samples.count() - samplesPerWidth - 1); + int last = qMin(_samples.count() - 1, first + samplesPerWidth); + + qreal scaleX = qreal(rect.width()) / qreal(samplesPerWidth); + + int t = 0; + + for(int ii = first; ii <= last; ++ii) { + int sampleTime = _samples.at(ii).sample[3] / 1000; + if(sampleTime != t) { + + int xEnd = rect.left() + scaleX * (ii - first); + p->drawLine(xEnd, rect.bottom(), xEnd, rect.bottom() + 7); + + QRect text(xEnd - 30, rect.bottom() + 10, 60, 30); + + p->drawText(text, Qt::AlignHCenter | Qt::AlignTop, QString::number(_samples.at(ii).sample[3])); + + t = sampleTime; + } + } + +} + +void QLineGraph::drawSample(QPainter *p, int s, const QRect &rect) +{ + if(_samples.isEmpty()) + return; + + int first = position; + if(first == -1) + first = qMax(0, _samples.count() - samplesPerWidth - 1); + int last = qMin(_samples.count() - 1, first + samplesPerWidth); + + qreal scaleY = rect.height() / resolutionForHeight; + qreal scaleX = qreal(rect.width()) / qreal(samplesPerWidth); + + int xEnd; + int lastXEnd = rect.left(); + + p->save(); + p->setPen(Qt::NoPen); + for(int ii = first + 1; ii <= last; ++ii) { + + xEnd = rect.left() + scaleX * (ii - first); + int yEnd = rect.bottom() - _samples.at(ii).sample[s] * scaleY; + + if (!(s == 0 && _samples.at(ii).isBreak)) + p->drawRect(QRect(lastXEnd, yEnd, scaleX, _samples.at(ii).sample[s] * scaleY)); + + lastXEnd = xEnd; + } + p->restore(); +} + +void QLineGraph::paintEvent(QPaintEvent *) +{ + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); + + + QRect r(50, 10, width() - 60, height() - 60); + p.setBrush(QColor("lightsteelblue")); + drawSample(&p, 0, r); + + p.setBrush(QColor("pink")); + drawSample(&p, 1, r); + + p.setBrush(QColor("green")); + drawSample(&p, 2, r); + + p.setBrush(Qt::NoBrush); + p.drawRect(r); + + for(int ii = 0; ii <= resolutionForHeight; ++ii) { + int y = 1 + r.bottom() - ii * r.height() / resolutionForHeight; + + if((ii % 10) == 0) { + p.drawLine(r.left() - 20, y, r.left(), y); + QRect text(r.left() - 20 - 53, y - 10, 50, 20); + p.drawText(text, Qt::AlignRight | Qt::AlignVCenter, QString::number(ii)); + } else { + p.drawLine(r.left() - 7, y, r.left(), y); + } + } + + drawTime(&p, r); +} + +class CanvasFrameRatePlugin : public QmlDebugClientPlugin +{ +Q_OBJECT +public: + CanvasFrameRatePlugin(QmlDebugClient *client); + +signals: + void sample(int, int, int, int, bool); + +protected: + virtual void messageReceived(const QByteArray &); + +private: + int la; + int lb; + int ld; +}; + +CanvasFrameRatePlugin::CanvasFrameRatePlugin(QmlDebugClient *client) +: QmlDebugClientPlugin(QLatin1String("CanvasFrameRate"), client), la(-1) +{ +} + +void CanvasFrameRatePlugin::messageReceived(const QByteArray &data) +{ + QByteArray rwData = data; + QDataStream stream(&rwData, QIODevice::ReadOnly); + + int a; int b; int c; int d; bool isBreak; + stream >> a >> b >> c >> d >> isBreak; + + if (la != -1) + emit sample(c, lb, la, ld, isBreak); + + la = a; + lb = b; + ld = d; +} + +CanvasFrameRate::CanvasFrameRate(QmlDebugClient *client, QWidget *parent) +: QWidget(parent) +{ + m_plugin = new CanvasFrameRatePlugin(client); + + QVBoxLayout *layout = new QVBoxLayout; + layout->setContentsMargins(0,0,0,0); + layout->setSpacing(0); + setLayout(layout); + + m_tabs = new QTabWidget(this); + layout->addWidget(m_tabs); + + QHBoxLayout *bottom = new QHBoxLayout; + layout->addLayout(bottom); + bottom->addStretch(2); + + QPushButton *pb = new QPushButton(tr("New Tab"), this); + QObject::connect(pb, SIGNAL(clicked()), this, SLOT(newTab())); + bottom->addWidget(pb); + + newTab(); +} + +void CanvasFrameRate::newTab() +{ + if (m_tabs->count()) { + QWidget *w = m_tabs->widget(m_tabs->count() - 1); + QObject::disconnect(m_plugin, SIGNAL(sample(int,int,int,int,bool)), + w, SLOT(addSample(int,int,int,int,bool))); + } + + int id = m_tabs->count(); + + QLineGraph *graph = new QLineGraph(this); + QObject::connect(m_plugin, SIGNAL(sample(int,int,int,int,bool)), + graph, SLOT(addSample(int,int,int,int,bool))); + + QString name = QLatin1String("Graph ") + QString::number(id); + m_tabs->addTab(graph, name); + m_tabs->setCurrentIndex(id); +} + +#include "canvasframerate.moc" diff --git a/tools/qmldebugger/canvasframerate.h b/tools/qmldebugger/canvasframerate.h new file mode 100644 index 0000000..c3e88ef --- /dev/null +++ b/tools/qmldebugger/canvasframerate.h @@ -0,0 +1,23 @@ +#ifndef CANVASFRAMERATE_H +#define CANVASFRAMERATE_H + +#include + +class QmlDebugClient; +class QTabWidget; +class CanvasFrameRate : public QWidget +{ + Q_OBJECT +public: + CanvasFrameRate(QmlDebugClient *, QWidget *parent = 0); + +private slots: + void newTab(); + +private: + QTabWidget *m_tabs; + QObject *m_plugin; +}; + +#endif // CANVASFRAMERATE_H + diff --git a/tools/qmldebugger/main.cpp b/tools/qmldebugger/main.cpp new file mode 100644 index 0000000..2c5be6c --- /dev/null +++ b/tools/qmldebugger/main.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "canvasframerate.h" +#include +#include +#include +#include +#include + +class Shell : public QWidget +{ +Q_OBJECT +public: + Shell(QWidget * = 0); + +private slots: + void connectToHost(); + void disconnectFromHost(); + +private: + QmlDebugClient client; + + QLineEdit *m_host; + QSpinBox *m_port; + QPushButton *m_connectButton; + QPushButton *m_disconnectButton; +}; + +Shell::Shell(QWidget *parent) +: QWidget(parent) +{ + QVBoxLayout *layout = new QVBoxLayout; + setLayout(layout); + + + QHBoxLayout *connectLayout = new QHBoxLayout; + layout->addLayout(connectLayout); + connectLayout->addStretch(2); + + m_host = new QLineEdit(this); + m_host->setText("localhost"); + connectLayout->addWidget(m_host); + m_port = new QSpinBox(this); + m_port->setMinimum(1024); + m_port->setMaximum(20000); + m_port->setValue(3768); + connectLayout->addWidget(m_port); + m_connectButton = new QPushButton(tr("Connect"), this); + QObject::connect(m_connectButton, SIGNAL(clicked()), + this, SLOT(connectToHost())); + connectLayout->addWidget(m_connectButton); + m_disconnectButton = new QPushButton(tr("Disconnect"), this); + QObject::connect(m_disconnectButton, SIGNAL(clicked()), + this, SLOT(disconnectFromHost())); + m_disconnectButton->setEnabled(false); + connectLayout->addWidget(m_disconnectButton); + + QTabWidget *tabs = new QTabWidget(this); + layout->addWidget(tabs); + + CanvasFrameRate *cfr = new CanvasFrameRate(&client, this); + tabs->addTab(cfr, tr("Frame Rate")); +} + +void Shell::connectToHost() +{ + m_connectButton->setEnabled(false); + m_disconnectButton->setEnabled(true); + client.connectToHost(m_host->text(), m_port->value()); +} + +void Shell::disconnectFromHost() +{ + m_connectButton->setEnabled(true); + m_disconnectButton->setEnabled(false); + client.disconnectFromHost(); +} + +int main(int argc, char ** argv) +{ + if(argc != 3) { + qWarning() << "Usage:" << argv[0] << "host port"; + return -1; + } + + QApplication app(argc, argv); + + Shell shell; +// shell.setFixedSize(1024, 768); + shell.show(); + + + return app.exec(); +} + +#include "main.moc" diff --git a/tools/qmldebugger/qmldebugger.pro b/tools/qmldebugger/qmldebugger.pro new file mode 100644 index 0000000..6af2909 --- /dev/null +++ b/tools/qmldebugger/qmldebugger.pro @@ -0,0 +1,10 @@ +DESTDIR = ../../bin +QT += network declarative +# Input +HEADERS += canvasframerate.h +SOURCES += main.cpp canvasframerate.cpp + +target.path=$$[QT_INSTALL_BINS] +INSTALLS += target + +CONFIG += console -- cgit v0.12 From 301fb6805644f1af28687794f7d888c04a1da12f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 26 May 2009 08:56:54 +1000 Subject: Fix compile when paint engine debugging is on. --- src/gui/painting/qpaintengine_raster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index c986e99..5b7ae48 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -6147,7 +6147,7 @@ void dumpClip(int width, int height, QClipData *clip) int y1 = 0; for (int i = 0; i < clip->count; ++i) { - QSpan *span = clip->spans + i; + QSpan *span = clip->spans() + i; for (int j = 0; j < span->len; ++j) clipImg.setPixel(span->x + j, span->y, 0xffffff00); x0 = qMin(x0, int(span->x)); -- cgit v0.12 From 93f0f38085e8fe2657ef3d7c5e24576d4475e85d Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 26 May 2009 09:01:37 +1000 Subject: Test cleanup. --- tests/benchmarks/qfxview/main.cpp | 182 ------ tests/benchmarks/qfxview/qfxview.pro | 16 - .../qfxview/testdata/tatwheel/editor/data.xml | 44 -- .../qfxview/testdata/tatwheel/pics/background.png | Bin 26508 -> 0 bytes .../qfxview/testdata/tatwheel/pics/background3.png | Bin 37671 -> 0 bytes .../qfxview/testdata/tatwheel/pics/battery.png | Bin 770 -> 0 bytes .../testdata/tatwheel/pics/calendar-blur.png | Bin 51439 -> 0 bytes .../qfxview/testdata/tatwheel/pics/calendar.png | Bin 10153 -> 0 bytes .../testdata/tatwheel/pics/callhistory-blur.png | Bin 57023 -> 0 bytes .../qfxview/testdata/tatwheel/pics/callhistory.png | Bin 13227 -> 0 bytes .../qfxview/testdata/tatwheel/pics/camera-blur.png | Bin 50955 -> 0 bytes .../qfxview/testdata/tatwheel/pics/camera.png | Bin 16126 -> 0 bytes .../testdata/tatwheel/pics/contacts-blur.png | Bin 51041 -> 0 bytes .../qfxview/testdata/tatwheel/pics/contacts.png | Bin 12177 -> 0 bytes .../testdata/tatwheel/pics/file-manager-blur.png | Bin 45164 -> 0 bytes .../testdata/tatwheel/pics/file-manager.png | Bin 8858 -> 0 bytes .../qfxview/testdata/tatwheel/pics/fire.png | Bin 1124 -> 0 bytes .../qfxview/testdata/tatwheel/pics/flask-blue.png | Bin 764 -> 0 bytes .../testdata/tatwheel/pics/flask-container.png | Bin 536 -> 0 bytes .../qfxview/testdata/tatwheel/pics/flask-front.png | Bin 962 -> 0 bytes .../qfxview/testdata/tatwheel/pics/flask-pink.png | Bin 747 -> 0 bytes .../testdata/tatwheel/pics/flask-yellow.png | Bin 775 -> 0 bytes .../qfxview/testdata/tatwheel/pics/ice.png | Bin 1112 -> 0 bytes .../testdata/tatwheel/pics/icon-reflection.png | Bin 7123 -> 0 bytes .../testdata/tatwheel/pics/internet-blur.png | Bin 57126 -> 0 bytes .../qfxview/testdata/tatwheel/pics/internet.png | Bin 24320 -> 0 bytes .../testdata/tatwheel/pics/menu-background1.png | Bin 2831 -> 0 bytes .../testdata/tatwheel/pics/menu-border1.png | Bin 926 -> 0 bytes .../testdata/tatwheel/pics/menu-border3.png | Bin 10153 -> 0 bytes .../testdata/tatwheel/pics/menu-highlight.png | Bin 3421 -> 0 bytes .../qfxview/testdata/tatwheel/pics/menubar.png | Bin 741 -> 0 bytes .../testdata/tatwheel/pics/messages-blur.png | Bin 44556 -> 0 bytes .../qfxview/testdata/tatwheel/pics/messages.png | Bin 11426 -> 0 bytes .../qfxview/testdata/tatwheel/pics/moon.png | Bin 1027 -> 0 bytes .../qfxview/testdata/tatwheel/pics/sad.png | Bin 1053 -> 0 bytes .../testdata/tatwheel/pics/settings-blur.png | Bin 50199 -> 0 bytes .../qfxview/testdata/tatwheel/pics/settings.png | Bin 8697 -> 0 bytes .../qfxview/testdata/tatwheel/pics/signal.png | Bin 739 -> 0 bytes .../qfxview/testdata/tatwheel/pics/smile.png | Bin 1051 -> 0 bytes .../qfxview/testdata/tatwheel/pics/star.png | Bin 262 -> 0 bytes .../qfxview/testdata/tatwheel/pics/sun.png | Bin 1021 -> 0 bytes .../qfxview/testdata/tatwheel/pics/titlebar.png | Bin 1041 -> 0 bytes .../qfxview/testdata/tatwheel/pics/wifi.png | Bin 782 -> 0 bytes .../qfxview/testdata/tatwheel/tat-wheel.xml | 68 -- tests/benchmarks/qmlpainting/qmlpainting.pro | 5 + tests/benchmarks/qmlpainting/tst_qmlpainting.cpp | 696 +++++++++++++++++++++ tests/benchmarks/qmlxmlparser/main.cpp | 96 --- tests/benchmarks/qmlxmlparser/qmlxmlparser.pro | 14 - .../benchmarks/qmlxmlparser/testdata/concept2.xml | 421 ------------- 49 files changed, 701 insertions(+), 841 deletions(-) delete mode 100644 tests/benchmarks/qfxview/main.cpp delete mode 100644 tests/benchmarks/qfxview/qfxview.pro delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/editor/data.xml delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/background.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/background3.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/battery.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/calendar-blur.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/calendar.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/callhistory-blur.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/callhistory.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/camera-blur.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/camera.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/contacts-blur.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/contacts.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/file-manager-blur.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/file-manager.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/fire.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-blue.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-container.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-front.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-pink.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-yellow.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/ice.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/icon-reflection.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/internet-blur.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/internet.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-background1.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-border1.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-border3.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-highlight.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/menubar.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/messages-blur.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/messages.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/moon.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/sad.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/settings-blur.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/settings.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/signal.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/smile.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/star.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/sun.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/titlebar.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/pics/wifi.png delete mode 100644 tests/benchmarks/qfxview/testdata/tatwheel/tat-wheel.xml create mode 100644 tests/benchmarks/qmlpainting/qmlpainting.pro create mode 100644 tests/benchmarks/qmlpainting/tst_qmlpainting.cpp delete mode 100644 tests/benchmarks/qmlxmlparser/main.cpp delete mode 100644 tests/benchmarks/qmlxmlparser/qmlxmlparser.pro delete mode 100644 tests/benchmarks/qmlxmlparser/testdata/concept2.xml diff --git a/tests/benchmarks/qfxview/main.cpp b/tests/benchmarks/qfxview/main.cpp deleted file mode 100644 index 787b113..0000000 --- a/tests/benchmarks/qfxview/main.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#include -#include -#include -#include -#include - -class tst_qfxview : public QObject -{ - Q_OBJECT - -private slots: - void render(); - void render_data(); - -private: - void waitForUpdates(QObject* obj, int howmany, int timeout = 10000); - bool eventFilter(QObject*, QEvent*); - - QString testdata(QString const&); - QString readFile(QString const&); - - int m_updateCount; - QEventLoop* m_eventLoop; - int m_updateLimit; -}; - -bool tst_qfxview::eventFilter(QObject*, QEvent* e) -{ - if (!m_eventLoop) { - return false; - } - - if (e->type() == QEvent::UpdateRequest) { - m_updateCount++; - if (m_updateCount >= m_updateLimit) { - m_eventLoop->quit(); - } - } - - return false; -} - -void tst_qfxview::waitForUpdates(QObject* obj, int howmany, int timeout) -{ - m_updateLimit = howmany; - m_updateCount = 0; - - QEventLoop loop; - m_eventLoop = &loop; - if (timeout > 0) - QTimer::singleShot(timeout, &loop, SLOT(quit())); - - obj->installEventFilter(this); - loop.exec(); - obj->removeEventFilter(this); - - m_eventLoop = 0; - - if (m_updateCount < howmany) { - QFAIL(qPrintable( - QString("Didn't receive %1 updates within %2 milliseconds (only got %3)") - .arg(howmany).arg(timeout).arg(m_updateCount) - )); - } -} - -void tst_qfxview::render() -{ - QFETCH(QString, xml); - QFETCH(QString, filename); - QFETCH(int, mode); - - static const int FRAMES = 100; - - QPixmap pm(800, 600); - - QFxView view((QSimpleCanvas::CanvasMode)mode); - view.setFixedSize(pm.size()); - if (!filename.isEmpty()) { - filename = testdata(filename); - xml = readFile(filename); - } - view.setXml(xml, filename); - QFileInfo fi(filename); - view.setPath(fi.path()); - - /* So we can reuse duiviewer examples... */ - QObject *dummyData = QML::newInstance(fi.path() + "/editor/data.xml"); - if (dummyData) { - QmlBindContext *ctxt = view.bindContext(); - ctxt->setProperty("obj", dummyData); - ctxt->addDefaultObject(dummyData); - dummyData->setParent(&view); - } - - view.show(); - view.raise(); - QTest::qWait(100); - view.activateWindow(); - QTest::qWait(100); - QVERIFY(view.isActiveWindow()); - - view.execute(); - - /* Set internal GfxAppClock to consistent timing (every tick is 5 ms) */ - { - GfxTimeLine tl; - tl.setMode(GfxTimeLine::Consistent); - } - - /* Render FRAMES amount of updates */ - QBENCHMARK { - waitForUpdates(&view, FRAMES); - if (QTest::currentTestFailed()) return; - } - - //view.dumpTiming(); -} - -void tst_qfxview::render_data() -{ - QTest::addColumn ("xml"); - QTest::addColumn ("filename"); - QTest::addColumn ("mode"); - - QTest::newRow("tatwheel-simplecanvas") - << QString() - << QString("tatwheel/tat-wheel.xml") - << int(QSimpleCanvas::SimpleCanvas) - ; - - QTest::newRow("tatwheel-graphicsview") - << QString() - << QString("tatwheel/tat-wheel.xml") - << int(QSimpleCanvas::GraphicsView) - ; - -} - -QString tst_qfxview::readFile(QString const& filename) -{ - QFile file(filename); - if (!file.open(QIODevice::ReadOnly)) { - qFatal("Could not open %s: %s", qPrintable(filename), qPrintable(file.errorString())); - } - QByteArray ba = file.readAll(); - return QString::fromLatin1(ba); -} - -QString tst_qfxview::testdata(QString const& name) -{ -#define _STR(X) #X -#define STR(X) _STR(X) - return QString("%1/testdata/%2").arg(STR(SRCDIR)).arg(name); -} - -int main(int argc, char** argv) -{ - /* Remove this when -graphicssystem raster is the default. */ - bool explicit_graphicssystem = false; - - QVector args; - for (int i = 0; i < argc; ++i) { - if (!strcmp(argv[i], "-graphicssystem")) - explicit_graphicssystem = true; - args << argv[i]; - } - - if (!explicit_graphicssystem) { - args << "-graphicssystem" << "raster"; - } - - argc = args.count(); - argv = const_cast(args.data()); - - QApplication app(argc, argv); - - tst_qfxview test; - return QTest::qExec(&test, argc, argv); -} - -#include "main.moc" diff --git a/tests/benchmarks/qfxview/qfxview.pro b/tests/benchmarks/qfxview/qfxview.pro deleted file mode 100644 index e7dd168..0000000 --- a/tests/benchmarks/qfxview/qfxview.pro +++ /dev/null @@ -1,16 +0,0 @@ -load(qttest_p4) -TEMPLATE = app -TARGET = tst_qfxview -DEPENDPATH += . -INCLUDEPATH += . - -CONFIG += release - -QT += declarative script - -DEFINES+=SRCDIR=\"$$PWD\" - -# Input -SOURCES += \ - main.cpp - diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/editor/data.xml b/tests/benchmarks/qfxview/testdata/tatwheel/editor/data.xml deleted file mode 100644 index 0a28d4f..0000000 --- a/tests/benchmarks/qfxview/testdata/tatwheel/editor/data.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - Internet - pics/internet - - - Calendar - pics/calendar - - - Contacts - pics/contacts - - - Camera - pics/camera - - - Messages - pics/messages - - - Call history - pics/callhistory - - - File manager - pics/file-manager - - - Settings - pics/settings - - - Call history - pics/callhistory - - - - - diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/background.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/background.png deleted file mode 100644 index 4b6f56e..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/background.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/background3.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/background3.png deleted file mode 100644 index 66cb522..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/background3.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/battery.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/battery.png deleted file mode 100644 index 4bd03d4..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/battery.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/calendar-blur.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/calendar-blur.png deleted file mode 100644 index 136ae80..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/calendar-blur.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/calendar.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/calendar.png deleted file mode 100644 index 0e63f1c..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/calendar.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/callhistory-blur.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/callhistory-blur.png deleted file mode 100644 index 5ed1c99..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/callhistory-blur.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/callhistory.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/callhistory.png deleted file mode 100644 index 6c26405..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/callhistory.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/camera-blur.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/camera-blur.png deleted file mode 100644 index 7285278..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/camera-blur.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/camera.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/camera.png deleted file mode 100644 index 710907f..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/camera.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/contacts-blur.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/contacts-blur.png deleted file mode 100644 index 5ba94c7..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/contacts-blur.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/contacts.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/contacts.png deleted file mode 100644 index 78bb885..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/contacts.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/file-manager-blur.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/file-manager-blur.png deleted file mode 100644 index 6ec1d55..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/file-manager-blur.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/file-manager.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/file-manager.png deleted file mode 100644 index e58a39b..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/file-manager.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/fire.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/fire.png deleted file mode 100644 index e1b40cf..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/fire.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-blue.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-blue.png deleted file mode 100644 index 3cb05ef..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-blue.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-container.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-container.png deleted file mode 100644 index dd34cbd..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-container.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-front.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-front.png deleted file mode 100644 index bed9e60..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-front.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-pink.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-pink.png deleted file mode 100644 index b84ee88..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-pink.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-yellow.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-yellow.png deleted file mode 100644 index 4108ea3..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/flask-yellow.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/ice.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/ice.png deleted file mode 100644 index 8191fbc..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/ice.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/icon-reflection.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/icon-reflection.png deleted file mode 100644 index 6c19e71..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/icon-reflection.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/internet-blur.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/internet-blur.png deleted file mode 100644 index 32dc564..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/internet-blur.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/internet.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/internet.png deleted file mode 100644 index 820ce34..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/internet.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-background1.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-background1.png deleted file mode 100644 index e84dc11..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-background1.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-border1.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-border1.png deleted file mode 100644 index e6dea40..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-border1.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-border3.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-border3.png deleted file mode 100644 index 1d8a571..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-border3.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-highlight.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-highlight.png deleted file mode 100644 index 3817b08..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menu-highlight.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menubar.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/menubar.png deleted file mode 100644 index 1b0380a..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/menubar.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/messages-blur.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/messages-blur.png deleted file mode 100644 index 3c62d53..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/messages-blur.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/messages.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/messages.png deleted file mode 100644 index a452d58..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/messages.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/moon.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/moon.png deleted file mode 100644 index cc3a3bc..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/moon.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/sad.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/sad.png deleted file mode 100644 index de90bc4..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/sad.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/settings-blur.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/settings-blur.png deleted file mode 100644 index f175161..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/settings-blur.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/settings.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/settings.png deleted file mode 100644 index 6e72796..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/settings.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/signal.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/signal.png deleted file mode 100644 index 7af4c24..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/signal.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/smile.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/smile.png deleted file mode 100644 index f6bf09f..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/smile.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/star.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/star.png deleted file mode 100644 index defbde5..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/star.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/sun.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/sun.png deleted file mode 100644 index b2092f1..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/sun.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/titlebar.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/titlebar.png deleted file mode 100644 index 40484d0..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/titlebar.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/pics/wifi.png b/tests/benchmarks/qfxview/testdata/tatwheel/pics/wifi.png deleted file mode 100644 index ada1d3b..0000000 Binary files a/tests/benchmarks/qfxview/testdata/tatwheel/pics/wifi.png and /dev/null differ diff --git a/tests/benchmarks/qfxview/testdata/tatwheel/tat-wheel.xml b/tests/benchmarks/qfxview/testdata/tatwheel/tat-wheel.xml deleted file mode 100644 index 6da6608..0000000 --- a/tests/benchmarks/qfxview/testdata/tatwheel/tat-wheel.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/benchmarks/qmlpainting/qmlpainting.pro b/tests/benchmarks/qmlpainting/qmlpainting.pro new file mode 100644 index 0000000..58e9775 --- /dev/null +++ b/tests/benchmarks/qmlpainting/qmlpainting.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qmlpainting + +SOURCES += tst_qmlpainting.cpp diff --git a/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp b/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp new file mode 100644 index 0000000..ae6f9a3 --- /dev/null +++ b/tests/benchmarks/qmlpainting/tst_qmlpainting.cpp @@ -0,0 +1,696 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +class tst_QmlPainting : public QObject +{ + Q_OBJECT + + public: + tst_QmlPainting() {} + +private slots: + void drawRoundedRect(); + void drawScaledRoundedRect(); + void drawTransformedRoundedRect(); + void drawAntialiasedRoundedRect(); + void drawScaledAntialiasedRoundedRect_data(); + void drawScaledAntialiasedRoundedRect(); + void drawTransformedAntialiasedRoundedRect_data(); + void drawTransformedAntialiasedRoundedRect(); + void drawImageRoundedRect(); + void drawScaledImageRoundedRect_data(); + void drawScaledImageRoundedRect(); + void drawTransformedImageRoundedRect_data(); + void drawTransformedImageRoundedRect(); + void drawScaleGridRoundedRect(); + void drawScaledScaleGridRoundedRect_data(); + void drawScaledScaleGridRoundedRect(); + void drawTransformedScaleGridRoundedRect_data(); + void drawTransformedScaleGridRoundedRect(); + void drawTransformedTransparentImage_data(); + void drawTransformedTransparentImage(); + void drawTransformedSemiTransparentImage_data(); + void drawTransformedSemiTransparentImage(); + void drawTransformedFilledImage_data(); + void drawTransformedFilledImage(); +}; + +const qreal inv_dist_to_plane = 1. / 1024.; +QTransform transformForAngle(qreal angle) +{ + QTransform transform; + + QTransform rotTrans; + rotTrans.translate(-40, 0); + QTransform rotTrans2; + rotTrans2.translate(40, 0); + + qreal rad = angle * 2. * M_PI / 360.; + qreal c = ::cos(rad); + qreal s = ::sin(rad); + + qreal x = 0; + qreal y = 80; + qreal z = 0; + + qreal len = x * x + y * y + z * z; + if (len != 1.) { + len = ::sqrt(len); + x /= len; + y /= len; + z /= len; + } + + QTransform rot(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*inv_dist_to_plane, + y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*inv_dist_to_plane, + 0, 0, 1); + + transform *= rotTrans; + transform *= rot; + transform *= rotTrans2; + + return transform; +} + +void tst_QmlPainting::drawRoundedRect() +{ + QImage surface(100, 100, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + p.setPen(QPen(Qt::black, 1)); + p.setBrush(Qt::red); + + QBENCHMARK { + p.drawRoundedRect(QRectF(.5, .5, 80, 80), 10, 10); + } + surface.save("regular.png"); +} + +void tst_QmlPainting::drawScaledRoundedRect() +{ + QImage surface(400, 400, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + p.setPen(QPen(Qt::black, 1)); + p.setBrush(Qt::red); + p.scale(3, 3); + + QBENCHMARK { + p.drawRoundedRect(10, 10, 80, 80, 10, 10); + } + surface.save("scaled.png"); +} + +void tst_QmlPainting::drawTransformedRoundedRect() +{ + QImage surface(400, 400, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + p.setPen(QPen(Qt::black, 1)); + p.setBrush(Qt::red); + + QBENCHMARK { + p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); + p.drawRoundedRect(100, 100, 80, 80, 10, 10); + } + surface.save("transformed.png"); +} + +void tst_QmlPainting::drawAntialiasedRoundedRect() +{ + QImage surface(100, 100, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + p.setRenderHint(QPainter::Antialiasing, true); + p.setPen(QPen(Qt::black, 1)); + p.setBrush(Qt::red); + + QBENCHMARK { + p.drawRoundedRect(QRectF(.5, .5, 80, 80), 10, 10); + } + surface.save("aar.png"); +} + +void tst_QmlPainting::drawScaledAntialiasedRoundedRect_data() +{ + QTest::addColumn("scale"); + + for (float i = 0; i < 3; i += .1) + QTest::newRow(QString(QLatin1String("scale=%1")).arg(i).toLatin1()) << i; +} + +void tst_QmlPainting::drawScaledAntialiasedRoundedRect() +{ + QFETCH(float, scale); + + QImage surface(400, 400, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + p.setRenderHint(QPainter::Antialiasing, true); + p.setPen(QPen(Qt::black, 1)); + p.setBrush(Qt::red); + p.scale(scale, scale); + + QBENCHMARK { + p.drawRoundedRect(10, 10, 80, 80, 10, 10); + } + surface.save("aas.png"); +} + +void tst_QmlPainting::drawTransformedAntialiasedRoundedRect_data() +{ + QTest::addColumn("transform"); + + for (float angle = 0; angle < 360; angle += 10) + QTest::newRow(QString(QLatin1String("angle=%1")).arg(angle).toLatin1()) << transformForAngle(angle); +} + +void tst_QmlPainting::drawTransformedAntialiasedRoundedRect() +{ + QFETCH(QTransform, transform); + + QImage surface(400, 400, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + p.setRenderHint(QPainter::Antialiasing, true); + p.setPen(QPen(Qt::black, 1)); + p.setBrush(Qt::red); + + QBENCHMARK { + p.setWorldTransform(transform); + p.drawRoundedRect(100, 100, 80, 80, 10, 10); + } + surface.save("aat.png"); +} + +void tst_QmlPainting::drawImageRoundedRect() +{ + //setup image + const int radius = 10; + QImage rectImage(81, 81, QImage::Format_ARGB32_Premultiplied); + rectImage.fill(0); + QPainter rp(&rectImage); + rp.setRenderHint(QPainter::Antialiasing); + rp.setPen(Qt::black); + rp.setBrush(Qt::red); + rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); + + //setup surface + QImage surface(100, 100, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + QBENCHMARK { + p.drawImage(0,0, rectImage); + } + surface.save("ri.png"); +} + +void tst_QmlPainting::drawScaledImageRoundedRect_data() +{ + QTest::addColumn("imageType"); + + QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; + QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; +} + +void tst_QmlPainting::drawScaledImageRoundedRect() +{ + QFETCH(int, imageType); + + //setup image + const int radius = 10; + QImage rectImage(81, 81, (QImage::Format)imageType); + rectImage.fill(0); + QPainter rp(&rectImage); + rp.setRenderHint(QPainter::Antialiasing); + rp.setPen(Qt::black); + rp.setBrush(Qt::red); + rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); + + //setup surface + QImage surface(400, 400, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + p.scale(3, 3); + + QBENCHMARK { + p.drawImage(0,0, rectImage); + } + surface.save("si.png"); +} + +void tst_QmlPainting::drawTransformedImageRoundedRect_data() +{ + QTest::addColumn("imageType"); + + QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; + QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; +} + +void tst_QmlPainting::drawTransformedImageRoundedRect() +{ + QFETCH(int, imageType); + + //setup image + const int radius = 10; + QImage rectImage(81, 81, (QImage::Format)imageType); + rectImage.fill(0); + QPainter rp(&rectImage); + rp.setRenderHint(QPainter::Antialiasing); + rp.setPen(Qt::black); + rp.setBrush(Qt::red); + rp.drawRoundedRect(QRectF(.5, .5, 80, 80), radius, radius); + + //setup surface + QImage surface(400, 400, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + QBENCHMARK { + p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); + p.drawImage(100,100, rectImage); + } + surface.save("ti.png"); +} + +//code from QFxRect for drawing rounded rects +void tst_QmlPainting::drawScaleGridRoundedRect() +{ + //setup image + const int pw = 1; + const int radius = 10; + QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, QImage::Format_ARGB32_Premultiplied); + rectImage.fill(0); + QPainter rp(&rectImage); + rp.setRenderHint(QPainter::Antialiasing); + rp.setPen(Qt::black); + rp.setBrush(Qt::red); + if (pw%2) + rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); + else + rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); + + //setup surface + QImage surface(100, 100, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + QBENCHMARK { + const int pw = 2; + int offset = int(radius+1.5+pw); + int width = 80; + int height = 80; + + int w = width+pw; + int h = height+pw; + int xOffset = offset; + int xSide = xOffset * 2; + bool xMiddles=true; + if (xSide > w) { + xMiddles=false; + xOffset = w/2 + 1; + xSide = xOffset * 2; + } + int yOffset = offset; + int ySide = yOffset * 2; + bool yMiddles=true; + if (ySide > h) { + yMiddles = false; + yOffset = h/2 + 1; + ySide = yOffset * 2; + } + + // Upper left + p.drawImage(QRect(-pw/2, -pw/2, xOffset, yOffset), rectImage, QRect(0, 0, xOffset, yOffset)); + + // Upper middle + if (xMiddles) + p.drawImage(QRect(xOffset-pw/2, -pw/2, width - xSide + pw, yOffset), rectImage, + QRect(rectImage.width()/2, 0, 1, yOffset)); + // Upper right + p.drawImage(QPoint(width-xOffset+pw/2, -pw/2), rectImage, + QRect(rectImage.width()-xOffset, 0, xOffset, yOffset)); + // Middle left + if (yMiddles) + p.drawImage(QRect(-pw/2, yOffset-pw/2, xOffset, height - ySide + pw), rectImage, + QRect(0, rectImage.height()/2, xOffset, 1)); + + // Middle + if (xMiddles && yMiddles) + p.drawImage(QRect(xOffset-pw/2, yOffset-pw/2, width - xSide + pw, height - ySide + pw), rectImage, + QRect(rectImage.width()/2, rectImage.height()/2, 1, 1)); + // Middle right + if (yMiddles) + p.drawImage(QRect(width-xOffset+pw/2, yOffset-pw/2, xOffset, height - ySide + pw), rectImage, + QRect(rectImage.width()-xOffset, rectImage.height()/2, xOffset, 1)); + // Lower left + p.drawImage(QPoint(-pw/2, height - yOffset + pw/2), rectImage, QRect(0, rectImage.height() - yOffset, xOffset, yOffset)); + + // Lower Middle + if (xMiddles) + p.drawImage(QRect(xOffset-pw/2, height - yOffset +pw/2, width - xSide + pw, yOffset), rectImage, + QRect(rectImage.width()/2, rectImage.height() - yOffset, 1, yOffset)); + // Lower Right + p.drawImage(QPoint(width-xOffset+pw/2, height - yOffset+pw/2), rectImage, + QRect(rectImage.width()-xOffset, rectImage.height() - yOffset, xOffset, yOffset)); + } + surface.save("rsg.png"); +} + +void tst_QmlPainting::drawScaledScaleGridRoundedRect_data() +{ + QTest::addColumn("scale"); + QTest::addColumn("imageType"); + + for (float i = 0; i < 3; i += .1) + QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB32_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB32_Premultiplied; + //for (float i = 0; i < 3; i += .1) + // QTest::newRow(QString(QLatin1String("scale=%1; imagetype=ARGB8565_Pre")).arg(i).toLatin1()) << i << (int)QImage::Format_ARGB8565_Premultiplied; +} + +//code from QFxRect for drawing rounded rects +void tst_QmlPainting::drawScaledScaleGridRoundedRect() +{ + QFETCH(float, scale); + QFETCH(int, imageType); + + //setup image + const int pw = 1; + const int radius = 10; + QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, (QImage::Format)imageType); + rectImage.fill(0); + QPainter rp(&rectImage); + rp.setRenderHint(QPainter::Antialiasing); + rp.setPen(Qt::black); + rp.setBrush(Qt::red); + if (pw%2) + rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); + else + rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); + + //setup surface + QImage surface(400, 400, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + p.scale(scale, scale); + + QBENCHMARK { + const int pw = 2; + int offset = int(radius+1.5+pw); + int width = 80; + int height = 80; + + int w = width+pw; + int h = height+pw; + int xOffset = offset; + int xSide = xOffset * 2; + bool xMiddles=true; + if (xSide > w) { + xMiddles=false; + xOffset = w/2 + 1; + xSide = xOffset * 2; + } + int yOffset = offset; + int ySide = yOffset * 2; + bool yMiddles=true; + if (ySide > h) { + yMiddles = false; + yOffset = h/2 + 1; + ySide = yOffset * 2; + } + + // Upper left + p.drawImage(QRect(10-pw/2, 10-pw/2, xOffset, yOffset), rectImage, QRect(0, 0, xOffset, yOffset)); + + // Upper middle + if (xMiddles) + p.drawImage(QRect(10+xOffset-pw/2, 10+-pw/2, width - xSide + pw, yOffset), rectImage, + QRect(rectImage.width()/2, 0, 1, yOffset)); + // Upper right + p.drawImage(QPoint(10+width-xOffset+pw/2, 10+-pw/2), rectImage, + QRect(rectImage.width()-xOffset, 0, xOffset, yOffset)); + // Middle left + if (yMiddles) + p.drawImage(QRect(10+-pw/2, 10+yOffset-pw/2, xOffset, height - ySide + pw), rectImage, + QRect(0, rectImage.height()/2, xOffset, 1)); + + // Middle + if (xMiddles && yMiddles) + p.drawImage(QRect(10+xOffset-pw/2, 10+yOffset-pw/2, width - xSide + pw, height - ySide + pw), rectImage, + QRect(rectImage.width()/2, rectImage.height()/2, 1, 1)); + // Middle right + if (yMiddles) + p.drawImage(QRect(10+width-xOffset+pw/2, 10+yOffset-pw/2, xOffset, height - ySide + pw), rectImage, + QRect(rectImage.width()-xOffset, rectImage.height()/2, xOffset, 1)); + // Lower left + p.drawImage(QPoint(10+-pw/2, 10+height - yOffset + pw/2), rectImage, QRect(0, rectImage.height() - yOffset, xOffset, yOffset)); + + // Lower Middle + if (xMiddles) + p.drawImage(QRect(10+xOffset-pw/2, 10+height - yOffset +pw/2, width - xSide + pw, yOffset), rectImage, + QRect(rectImage.width()/2, rectImage.height() - yOffset, 1, yOffset)); + // Lower Right + p.drawImage(QPoint(10+width-xOffset+pw/2, 10+height - yOffset+pw/2), rectImage, + QRect(rectImage.width()-xOffset, rectImage.height() - yOffset, xOffset, yOffset)); + } + surface.save("ssg.png"); +} + +void tst_QmlPainting::drawTransformedScaleGridRoundedRect_data() +{ + QTest::addColumn("transform"); + QTest::addColumn("imageType"); + + for (float angle = 0; angle < 360; angle += 10) + QTest::newRow(QString(QLatin1String("angle=%1; imagetype=ARGB32_Pre")).arg(angle).toLatin1()) << transformForAngle(angle) << (int)QImage::Format_ARGB32_Premultiplied; + //for (float angle = 0; angle < 360; angle += 10) + // QTest::newRow(QString(QLatin1String("angle=%1; imagetype=ARGB8565_Pre")).arg(angle).toLatin1()) << transformForAngle(angle) << (int)QImage::Format_ARGB8565_Premultiplied; + +} + +//code from QFxRect for drawing rounded rects +void tst_QmlPainting::drawTransformedScaleGridRoundedRect() +{ + QFETCH(QTransform, transform); + QFETCH(int, imageType); + + //setup image + const int pw = 1; + const int radius = 10; + QImage rectImage(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2, (QImage::Format)imageType); + rectImage.fill(0); + QPainter rp(&rectImage); + rp.setRenderHint(QPainter::Antialiasing); + rp.setPen(Qt::black); + rp.setBrush(Qt::red); + if (pw%2) + rp.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, rectImage.width()-(pw+1), rectImage.height()-(pw+1)), radius, radius); + else + rp.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, rectImage.width()-pw, rectImage.height()-pw), radius, radius); + + //setup surface + QImage surface(400, 400, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + QBENCHMARK { + p.setWorldTransform(transform); + const int pw = 2; + int offset = int(radius+1.5+pw); + int width = 80; + int height = 80; + + int w = width+pw; + int h = height+pw; + int xOffset = offset; + int xSide = xOffset * 2; + bool xMiddles=true; + if (xSide > w) { + xMiddles=false; + xOffset = w/2 + 1; + xSide = xOffset * 2; + } + int yOffset = offset; + int ySide = yOffset * 2; + bool yMiddles=true; + if (ySide > h) { + yMiddles = false; + yOffset = h/2 + 1; + ySide = yOffset * 2; + } + + // Upper left + p.drawImage(QRect(100-pw/2, 100-pw/2, xOffset, yOffset), rectImage, QRect(0, 0, xOffset, yOffset)); + + // Upper middle + if (xMiddles) + p.drawImage(QRect(100+xOffset-pw/2, 100+-pw/2, width - xSide + pw, yOffset), rectImage, + QRect(rectImage.width()/2, 0, 1, yOffset)); + // Upper right + p.drawImage(QPoint(100+width-xOffset+pw/2, 100+-pw/2), rectImage, + QRect(rectImage.width()-xOffset, 0, xOffset, yOffset)); + // Middle left + if (yMiddles) + p.drawImage(QRect(100+-pw/2, 100+yOffset-pw/2, xOffset, height - ySide + pw), rectImage, + QRect(0, rectImage.height()/2, xOffset, 1)); + + // Middle + if (xMiddles && yMiddles) + p.drawImage(QRect(100+xOffset-pw/2, 100+yOffset-pw/2, width - xSide + pw, height - ySide + pw), rectImage, + QRect(rectImage.width()/2, rectImage.height()/2, 1, 1)); + // Middle right + if (yMiddles) + p.drawImage(QRect(100+width-xOffset+pw/2, 100+yOffset-pw/2, xOffset, height - ySide + pw), rectImage, + QRect(rectImage.width()-xOffset, rectImage.height()/2, xOffset, 1)); + // Lower left + p.drawImage(QPoint(100+-pw/2, 100+height - yOffset + pw/2), rectImage, QRect(0, rectImage.height() - yOffset, xOffset, yOffset)); + + // Lower Middle + if (xMiddles) + p.drawImage(QRect(100+xOffset-pw/2, 100+height - yOffset +pw/2, width - xSide + pw, yOffset), rectImage, + QRect(rectImage.width()/2, rectImage.height() - yOffset, 1, yOffset)); + // Lower Right + p.drawImage(QPoint(100+width-xOffset+pw/2, 100+height - yOffset+pw/2), rectImage, + QRect(rectImage.width()-xOffset, rectImage.height() - yOffset, xOffset, yOffset)); + } + surface.save("tsg.png"); +} + +void tst_QmlPainting::drawTransformedTransparentImage_data() +{ + QTest::addColumn("imageType"); + + QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; + QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; +} + +void tst_QmlPainting::drawTransformedTransparentImage() +{ + QFETCH(int, imageType); + + //setup image + QImage transImage(200, 200, (QImage::Format)imageType); + transImage.fill(0); + + //setup surface + QImage surface(200, 200, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + QBENCHMARK { + p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); + p.drawImage(0,0, transImage); + } +} + +void tst_QmlPainting::drawTransformedSemiTransparentImage_data() +{ + QTest::addColumn("imageType"); + + QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; + QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; +} + +void tst_QmlPainting::drawTransformedSemiTransparentImage() +{ + QFETCH(int, imageType); + + //setup image + QImage transImage(200, 200, (QImage::Format)imageType); + transImage.fill(QColor(0,0,0, 128).rgba()); + + //setup surface + QImage surface(200, 200, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + QBENCHMARK { + p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); + p.drawImage(0,0, transImage); + } +} + +void tst_QmlPainting::drawTransformedFilledImage_data() +{ + QTest::addColumn("imageType"); + + QTest::newRow("imagetype=ARGB32_Pre") << (int)QImage::Format_ARGB32_Premultiplied; + QTest::newRow("imagetype=ARGB8565_Pre") << (int)QImage::Format_ARGB8565_Premultiplied; +} + +void tst_QmlPainting::drawTransformedFilledImage() +{ + QFETCH(int, imageType); + + //setup image + QImage filledImage(200, 200, (QImage::Format)imageType); + filledImage.fill(QColor(0,0,0).rgb()); + + //setup surface + QImage surface(200, 200, QImage::Format_RGB16); + surface.fill(QColor(255,255,255).rgb()); + QPainter p(&surface); + + QBENCHMARK { + p.setWorldTransform(QTransform(0.956957, 0, 0.000704124, 0, 1, 0, 16.141, 0, 0.735953)); + p.drawImage(0,0, filledImage); + } +} + +QTEST_MAIN(tst_QmlPainting) + +#include "tst_qmlpainting.moc" diff --git a/tests/benchmarks/qmlxmlparser/main.cpp b/tests/benchmarks/qmlxmlparser/main.cpp deleted file mode 100644 index 17dc7f3..0000000 --- a/tests/benchmarks/qmlxmlparser/main.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include - -class tst_qmlxmlparser : public QObject -{ - Q_OBJECT - -public: - enum XmlParser { ParserQXmlStreamReader = 0, ParserQmlComponent }; - -private slots: - void parse(); - void parse_data(); - -private: - QString readFile(QString const&); -}; - -/* - Benchmark the parsing of Qml, using QXmlStreamReader as a baseline. - This gives an idea of the overhead Qml imposes over the top of plain XML parsing. -*/ -void tst_qmlxmlparser::parse() -{ - QFETCH(QString, xml); - QFETCH(int, parser); - - if (parser == ParserQXmlStreamReader) { - QBENCHMARK { - QXmlStreamReader parser(xml); - while (!parser.atEnd()) parser.readNext(); - } - } - else if (parser == ParserQmlComponent) { - QByteArray ba = xml.toLatin1(); - QBENCHMARK { - QmlComponent qmlc(ba); - } - } -} - -void tst_qmlxmlparser::parse_data() -{ - QTest::addColumn("xml"); - QTest::addColumn ("parser"); - - QTest::newRow("empty-qxml") - << QString() - << (int)ParserQXmlStreamReader; - - QTest::newRow("empty-qml") - << QString() - << (int)ParserQmlComponent; - - { - QString xml = QString::fromLatin1(""); - - QTest::newRow("simple-qxml") - << xml - << (int)ParserQXmlStreamReader; - - QTest::newRow("simple-qml") - << xml - << (int)ParserQmlComponent; - } - - { - QString xml = readFile("concept2.xml"); - - QTest::newRow("concept2-qxml") - << xml - << (int)ParserQXmlStreamReader; - - QTest::newRow("concept2-qml") - << xml - << (int)ParserQmlComponent; - } -} - -QString tst_qmlxmlparser::readFile(QString const& filename) -{ -#define _STR(X) #X -#define STR(X) _STR(X) - QFile file(QString("%1/testdata/%2").arg(STR(SRCDIR)).arg(filename)); - if (!file.open(QIODevice::ReadOnly)) { - qFatal("Could not open %s: %s", qPrintable(filename), qPrintable(file.errorString())); - } - QByteArray ba = file.readAll(); - return QString::fromLatin1(ba); -} - - -QTEST_MAIN(tst_qmlxmlparser) - -#include "main.moc" diff --git a/tests/benchmarks/qmlxmlparser/qmlxmlparser.pro b/tests/benchmarks/qmlxmlparser/qmlxmlparser.pro deleted file mode 100644 index e31c692..0000000 --- a/tests/benchmarks/qmlxmlparser/qmlxmlparser.pro +++ /dev/null @@ -1,14 +0,0 @@ -load(qttest_p4) -TEMPLATE = app -TARGET = tst_qmlxmlparser -DEPENDPATH += . -INCLUDEPATH += . - -CONFIG += release - -QT += declarative xml - -DEFINES+=SRCDIR=\"$$PWD\" - -# Input -SOURCES += main.cpp diff --git a/tests/benchmarks/qmlxmlparser/testdata/concept2.xml b/tests/benchmarks/qmlxmlparser/testdata/concept2.xml deleted file mode 100644 index 67c625d..0000000 --- a/tests/benchmarks/qmlxmlparser/testdata/concept2.xml +++ /dev/null @@ -1,421 +0,0 @@ - - - -