Skip to content

Commit

Permalink
[qml] Only calculate FPS and do not draw it
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej committed Oct 17, 2013
1 parent 5155f79 commit 807af16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 54 deletions.
60 changes: 18 additions & 42 deletions src/qml/painter/GlslPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,6 @@
#include "core/VideoFrame.h"
#include "qml/painter/GlslPainter.h"

#if !defined(Q_OS_WIN32)
void GlslPainter::calculateFPS()
{
if (_fps.lastTime.isNull())
_fps.lastTime = QTime::currentTime();
QTime time = QTime::currentTime();

int delta = _fps.lastTime.msecsTo(time);
if (delta > 2000) {
_fps.value = 1000.0 * _fps.frames / qreal(delta);
if (_fps.value < 20.0)
qWarning() << "Drawing less than 20 frames per second!";
_fps.lastTime = time;
_fps.frames = 0;
}

++_fps.frames;
}

void GlslPainter::addFPSOverlay()
{
if (_fps.value != _fps.imagedValue) {
// Update image
_fps.img.fill(Qt::blue);
QPainter painter(&(_fps.img));
painter.setPen(QColor(Qt::white));
painter.drawText(0, 16, QString::number((int)_fps.value));
painter.end();
}

GLuint id = _context->bindTexture(_fps.img);
_context->drawTexture(QPointF(0, 0), id);
_context->deleteTexture(id);

_fps.imagedValue = _fps.value;
}
#endif

GlslPainter::GlslPainter()
: _program(0) { }

Expand Down Expand Up @@ -237,9 +199,23 @@ void GlslPainter::paint(QPainter *painter,
_program->release();
painter->endNativePainting();

#if !defined(Q_OS_WIN)
// TODO: FPS optional
calculateFPS();
addFPSOverlay();
#endif
}

void GlslPainter::calculateFPS()
{
if (_fps.lastTime.isNull())
_fps.lastTime = QTime::currentTime();
QTime time = QTime::currentTime();

int delta = _fps.lastTime.msecsTo(time);
if (delta > 2000) {
_fps.value = 1000.0 * _fps.frames / qreal(delta);
if (_fps.value < 20.0)
qWarning() << "Drawing less than 20 frames per second!";
_fps.lastTime = time;
_fps.frames = 0;
}

++_fps.frames;
}
14 changes: 2 additions & 12 deletions src/qml/painter/GlslPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
#define VLCQT_PHONON_GLSLPAINTER_H_

#include <QtCore/QRectF>
#include <QtCore/QTime>
#include <QtQuick/QQuickWindow>

#if !defined(Q_OS_WIN32)
#include <QtCore/QTime>
#endif

#include "qml/painter/GlPainter.h"

class QOpenGLShaderProgram;
Expand All @@ -51,25 +48,18 @@ class GlslPainter : public GlPainter
private:
QOpenGLShaderProgram *_program;

#if !defined(Q_OS_WIN32)
void calculateFPS();
void addFPSOverlay();

struct FPS {
FPS() : value(0),
imagedValue(0),
frames(0),
img(32, 32, QImage::Format_ARGB32) { }
frames(0) { }

qreal value;
qreal imagedValue;
quint64 frames;
QTime lastTime;
QImage img;
};

struct FPS _fps;
#endif
};

#endif // VLCQT_PHONON_GLSLPAINTER_H_

0 comments on commit 807af16

Please sign in to comment.