summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/util/qfxview.cpp63
-rw-r--r--tools/qmldebugger/canvasframerate.cpp38
2 files changed, 78 insertions, 23 deletions
diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp
index 9a2845c..f67dc75 100644
--- a/src/declarative/util/qfxview.cpp
+++ b/src/declarative/util/qfxview.cpp
@@ -60,11 +60,70 @@
#include <QtDeclarative/qmlengine.h>
#include <QtDeclarative/qmlcontext.h>
#include <QtDeclarative/qmldebug.h>
+#include <QtDeclarative/qmldebugservice.h>
+#include <QtCore/qabstractanimation.h>
QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(frameRateDebug, QML_SHOW_FRAMERATE)
+class QFxViewDebugServer;
+class FrameBreakAnimation : public QAbstractAnimation
+{
+public:
+ FrameBreakAnimation(QFxViewDebugServer *s)
+ : QAbstractAnimation((QObject*)s), server(s)
+ {
+ start();
+ }
+
+ virtual int duration() const { return -1; }
+ virtual void updateCurrentTime(int msecs);
+
+private:
+ QFxViewDebugServer *server;
+};
+
+class QFxViewDebugServer : public QmlDebugService
+{
+public:
+ QFxViewDebugServer(QObject *parent = 0) : QmlDebugService(QLatin1String("CanvasFrameRate"), parent), breaks(0)
+ {
+ timer.start();
+ new FrameBreakAnimation(this);
+ }
+
+ void addTiming(int pe, int tbf)
+ {
+ if (!isEnabled())
+ return;
+
+ bool isFrameBreak = breaks > 1;
+ breaks = 0;
+ int e = timer.elapsed();
+ QByteArray data;
+ QDataStream ds(&data, QIODevice::WriteOnly);
+ ds << (int)pe << (int)pe << (int)tbf << (int)e
+ << (bool)isFrameBreak;
+ sendMessage(data);
+ }
+
+ void frameBreak() { ++breaks; }
+
+private:
+ QTime timer;
+ int breaks;
+};
+
+Q_GLOBAL_STATIC(QFxViewDebugServer, qfxViewDebugServer);
+
+void FrameBreakAnimation::updateCurrentTime(int msecs)
+{
+ Q_UNUSED(msecs);
+ server->frameBreak();
+}
+
+
static QVariant stringToKeySequence(const QString &str)
{
return QVariant::fromValue(QKeySequence(str));
@@ -487,9 +546,11 @@ void QFxView::resizeEvent(QResizeEvent *e)
void QFxView::paintEvent(QPaintEvent *event)
{
int time = 0;
- if (frameRateDebug())
+ if (frameRateDebug() || QFxViewDebugServer::isDebuggingEnabled())
time = d->frameTimer.restart();
QGraphicsView::paintEvent(event);
+ if (QFxViewDebugServer::isDebuggingEnabled())
+ qfxViewDebugServer()->addTiming(d->frameTimer.elapsed(), time);
if (frameRateDebug())
qDebug() << "paintEvent:" << d->frameTimer.elapsed() << "time since last frame:" << time;
}
diff --git a/tools/qmldebugger/canvasframerate.cpp b/tools/qmldebugger/canvasframerate.cpp
index d0be579..ae514a5 100644
--- a/tools/qmldebugger/canvasframerate.cpp
+++ b/tools/qmldebugger/canvasframerate.cpp
@@ -25,7 +25,7 @@ public:
void setPosition(int);
public slots:
- void addSample(int, int, int, int, bool);
+ void addSample(int, int, int, bool);
protected:
virtual void paintEvent(QPaintEvent *);
@@ -39,7 +39,7 @@ private:
void drawSample(QPainter *, int, const QRect &);
void drawTime(QPainter *, const QRect &);
struct Sample {
- int sample[4];
+ int sample[3];
bool isBreak;
};
QList<Sample> _samples;
@@ -95,14 +95,13 @@ void QLineGraph::updateScrollbar()
ignoreScroll = false;
}
-void QLineGraph::addSample(int a, int b, int c, int d, bool isBreak)
+void QLineGraph::addSample(int a, int b, 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;
+ s.sample[2] = d;
_samples << s;
updateScrollbar();
update();
@@ -128,7 +127,7 @@ void QLineGraph::drawTime(QPainter *p, const QRect &rect)
int t = 0;
for(int ii = first; ii <= last; ++ii) {
- int sampleTime = _samples.at(ii).sample[3] / 1000;
+ int sampleTime = _samples.at(ii).sample[2] / 1000;
if(sampleTime != t) {
int xEnd = rect.left() + scaleX * (ii - first);
@@ -136,7 +135,7 @@ void QLineGraph::drawTime(QPainter *p, const QRect &rect)
QRect text(xEnd - 30, rect.bottom() + 10, 60, 30);
- p->drawText(text, Qt::AlignHCenter | Qt::AlignTop, QString::number(_samples.at(ii).sample[3]));
+ p->drawText(text, Qt::AlignHCenter | Qt::AlignTop, QString::number(_samples.at(ii).sample[2]));
t = sampleTime;
}
@@ -188,9 +187,6 @@ void QLineGraph::paintEvent(QPaintEvent *)
p.setBrush(QColor("pink"));
drawSample(&p, 1, r);
- p.setBrush(QColor("green"));
- drawSample(&p, 2, r);
-
p.setBrush(Qt::NoBrush);
p.drawRect(r);
@@ -216,19 +212,18 @@ public:
CanvasFrameRatePlugin(QmlDebugConnection *client);
signals:
- void sample(int, int, int, int, bool);
+ void sample(int, int, int, bool);
protected:
virtual void messageReceived(const QByteArray &);
private:
- int la;
int lb;
int ld;
};
CanvasFrameRatePlugin::CanvasFrameRatePlugin(QmlDebugConnection *client)
-: QmlDebugClient(QLatin1String("CanvasFrameRate"), client), la(-1)
+: QmlDebugClient(QLatin1String("CanvasFrameRate"), client), lb(-1)
{
}
@@ -237,13 +232,12 @@ 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;
+ int b; int c; int d; bool isBreak;
+ stream >> b >> c >> d >> isBreak;
- if (la != -1)
- emit sample(c, lb, la, ld, isBreak);
+ if (lb != -1)
+ emit sample(c, lb, ld, isBreak);
- la = a;
lb = b;
ld = d;
}
@@ -281,15 +275,15 @@ 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)));
+ QObject::disconnect(m_plugin, SIGNAL(sample(int,int,int,bool)),
+ w, SLOT(addSample(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)));
+ QObject::connect(m_plugin, SIGNAL(sample(int,int,int,bool)),
+ graph, SLOT(addSample(int,int,int,bool)));
QString name = QLatin1String("Graph ") + QString::number(id);
m_tabs->addTab(graph, name);