summaryrefslogtreecommitdiffstats
path: root/src/declarative/util
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-09-21 06:52:06 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-09-21 06:52:06 (GMT)
commit7423f732ce01ca18788543bd4cfc921b55e2f17c (patch)
treea6c15ba9d638bd66937d036b866fa4301e58f539 /src/declarative/util
parent26bd84ec3625c825c04228b76dd37cd5e75fb36b (diff)
downloadQt-7423f732ce01ca18788543bd4cfc921b55e2f17c.zip
Qt-7423f732ce01ca18788543bd4cfc921b55e2f17c.tar.gz
Qt-7423f732ce01ca18788543bd4cfc921b55e2f17c.tar.bz2
Get the framerate monitor working again.
Diffstat (limited to 'src/declarative/util')
-rw-r--r--src/declarative/util/qfxview.cpp63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp
index 19dfe2c..eb767a0 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;
}