diff options
Diffstat (limited to 'src/declarative/canvas')
-rw-r--r-- | src/declarative/canvas/canvas.pri | 4 | ||||
-rw-r--r-- | src/declarative/canvas/monitor/main.cpp | 287 | ||||
-rw-r--r-- | src/declarative/canvas/monitor/monitor.pro | 8 | ||||
-rw-r--r-- | src/declarative/canvas/qsimplecanvas.cpp | 18 | ||||
-rw-r--r-- | src/declarative/canvas/qsimplecanvas_p.h | 6 | ||||
-rw-r--r-- | src/declarative/canvas/qsimplecanvasdebugplugin.cpp (renamed from src/declarative/canvas/qsimplecanvasserver.cpp) | 71 | ||||
-rw-r--r-- | src/declarative/canvas/qsimplecanvasdebugplugin_p.h (renamed from src/declarative/canvas/qsimplecanvasserver_p.h) | 23 |
7 files changed, 35 insertions, 382 deletions
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 <QApplication> -#include <QWidget> -#include <QPainter> -#include <QTcpSocket> -#include <QScrollBar> - -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<Sample> _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 <glheaders.h> #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<QSimpleCanvasItem *> focusPanels; QHash<QSimpleCanvasItem *, QSimpleCanvasItem *> focusPanelData; diff --git a/src/declarative/canvas/qsimplecanvasserver.cpp b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp index ed781b8..0ce5378 100644 --- a/src/declarative/canvas/qsimplecanvasserver.cpp +++ b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp @@ -39,11 +39,8 @@ ** ****************************************************************************/ -#include "qsimplecanvasserver_p.h" +#include "qsimplecanvasdebugplugin_p.h" #include "qdebug.h" -#ifndef Q_OS_WIN32 -#include <arpa/inet.h> -#endif #include <QtCore/qabstractanimation.h> QT_BEGIN_NAMESPACE @@ -51,7 +48,7 @@ QT_BEGIN_NAMESPACE class FrameBreakAnimation : public QAbstractAnimation { public: - FrameBreakAnimation(QSimpleCanvasServer *s) + FrameBreakAnimation(QSimpleCanvasDebugPlugin *s) : QAbstractAnimation(s), server(s) { start(); @@ -63,72 +60,34 @@ public: } private: - QSimpleCanvasServer *server; + QSimpleCanvasDebugPlugin *server; }; -QSimpleCanvasServer::QSimpleCanvasServer(int port, QObject *parent) -: QObject(parent), _breaks(0), _tcpServer(new QTcpServer(this)) +QSimpleCanvasDebugPlugin::QSimpleCanvasDebugPlugin(QObject *parent) +: QmlDebugServerPlugin("CanvasFrameRate", parent), _breaks(0) { - 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() +void QSimpleCanvasDebugPlugin::addTiming(quint32 paint, + quint32 repaint, + quint32 timeBetweenFrames) { - 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()); + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << (int)paint << (int)repaint << (int)timeBetweenFrames << (int)e + << (bool)isFrameBreak; + sendMessage(data); } -void QSimpleCanvasServer::frameBreak() +void QSimpleCanvasDebugPlugin::frameBreak() { _breaks++; } -void QSimpleCanvasServer::disconnected() -{ - QTcpSocket *socket = static_cast<QTcpSocket *>(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/qsimplecanvasdebugplugin_p.h index ce04e8d..0c76f38 100644 --- a/src/declarative/canvas/qsimplecanvasserver_p.h +++ b/src/declarative/canvas/qsimplecanvasdebugplugin_p.h @@ -39,37 +39,30 @@ ** ****************************************************************************/ -#ifndef QSIMPLECANVASSERVER_P_H -#define QSIMPLECANVASSERVER_P_H +#ifndef QSIMPLECANVASDEBUGPLUGIN_P_H +#define QSIMPLECANVASDEBUGPLUGIN_P_H #include "qobject.h" #include "qtcpserver.h" #include "qtcpsocket.h" #include "qdatetime.h" - +#include <QtDeclarative/qmldebugserver.h> QT_BEGIN_NAMESPACE -class QSimpleCanvasServer : public QObject +class QSimpleCanvasDebugPlugin : public QmlDebugServerPlugin { -Q_OBJECT public: - QSimpleCanvasServer(int port, QObject *parent); + QSimpleCanvasDebugPlugin(QObject *parent = 0); void addTiming(quint32, quint32, quint32); -private Q_SLOTS: - void newConnection(); - void disconnected(); - private: friend class FrameBreakAnimation; void frameBreak(); int _breaks; - - QTcpServer *_tcpServer; - QList<QTcpSocket *> _tcpClients; QTime _time; }; - QT_END_NAMESPACE -#endif // GFXCANVASSERVER_P_H + +#endif // QSIMPLECANVASDEBUGPLUGIN_P_H + |